導航:首頁 > 操作系統 > android開發button

android開發button

發布時間:2022-11-02 09:57:37

android開發中點擊button無反應大神來看看這個代碼的問題在哪裡

把 button_listener = new Button.OnClickListener() {
public void onClick(View v) {
//setTitle("哎呦,button被點了一下");
Intent intent=new Intent(MainActivity.this,edText.class);
startActivity(intent);
} 這段放到 onCreate 方法外面

Button.OnClickListener button_listener = new Button.OnClickListener() {
public void onClick(View v) {
//setTitle("哎呦,button被點了一下");
Intent intent=new Intent(MainActivity.this,edText.class);
startActivity(intent);
}

② android開發 如何隨機選button

10個button的引用放到MAP<int,Button>中,key為1-10,value為10個button的引用,
然後取1-10隨機數,再通過取到的隨機數去map中取button
OK了

③ 如何在android當中實現Button操作

你可以現在布局文件layout中添加button控制項,然後對其屬性設置,最後在src文件中,編寫java文件,對該按鈕的功能進行設置,並監聽按鈕事件

④ Android開發中,如何給動態生成的Button指定Style樣式

自定義樣式方法,可以直接通過定義xml文件來實現不同的樣式:
只需要修改button_style文件,同樣三種狀態分開定義:
Xml代碼
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<gradient android:startColor="#0d76e1" android:endColor="#0d76e1"
android:angle="270" />
<stroke android:width="1dip" android:color="#f403c9" />
<corners android:radius="2dp" />
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />
</shape>
</item>

<item android:state_focused="true">
<shape>
<gradient android:startColor="#ffc2b7" android:endColor="#ffc2b7"
android:angle="270" />
<stroke android:width="1dip" android:color="#f403c9" />
<corners android:radius="2dp" />
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />
</shape>
</item>

<item>
<shape>
<gradient android:startColor="#000000" android:endColor="#ffffff"
android:angle="180" />
<stroke android:width="1dip" android:color="#f403c9" />
<corners android:radius="5dip" />
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />
</shape>
</item>
</selector>

gradient 主體漸變 startColor開始顏色,endColor結束顏色 ,angle開始漸變的角度(值只能為90的倍數,0時為左到右漸變,90時為下到上漸變,依次逆時針類推)
stroke 邊框 width 邊框寬度,color 邊框顏色
corners 圓角 radius 半徑,0為直角
padding text值的相對位置

⑤ android中button有幾種狀態

Android中,button按鈕通常有三個狀態:

1. normal(正常狀態);
2. focus(焦點狀態);
3. pressed(按下狀態)
4. selected(選中狀態)

注意:按下後未松開前是pressed,表示按下。
松開後當前項目獲得焦點,是focused。
focused的項只有一個,selected是當選中該按鈕時顯示的狀態。

⑥ Android 開發裡面如何點擊Button將EditText裡面的內容顯示在textView里

1、添加button的單擊事件
2、獲取edittext的內容
3、往textview中賦值
示例:
Button btn = (Button)findViewById(R.id.xxx);//獲取按鈕
btn.setOnClickListener(new View.OnClickListener() {
//設置按鈕單擊事件
@Override
public void onClick(View v) {
EditText et = (EditText)findViewById(R.id.xxxx);//獲取edittext組件
TextView tv = (TextView)findViewById(R.id.xxxx);//獲取textview組件
String cn = et.getText().toString();//獲取edittext中填寫的內容
tv.setText(cn);//在textview中顯示
}
});

⑦ android開發中,button的text(settext方法)可以動態的設置嗎

可以。

1、通過id獲取button組件

Buttonbtn=(Button)findViewById(R.id.xxxx);//獲取button組件對象

2、通過setText方法改變button的text屬性

btn.setText("改變後的值");//改變button的文本顯示
閱讀全文

與android開發button相關的資料

熱點內容
單反照片批量壓縮 瀏覽:340
javazip壓縮目錄 瀏覽:712
89c52單片機晶振 瀏覽:206
pdf轉jpgmac 瀏覽:799
65壓縮機多少錢 瀏覽:120
同類型服務app如何脫穎而出 瀏覽:762
mtm月線金叉選股預警公式源碼 瀏覽:227
javasapwebservice 瀏覽:709
程序員老了去做什麼 瀏覽:404
linux小括弧 瀏覽:773
已加密的u盤怎麼清空 瀏覽:433
怎麼拿到伺服器許可權 瀏覽:192
延時攝影app如何保存 瀏覽:195
程序員轉正申請職級怎麼寫 瀏覽:874
closelinuxsocket 瀏覽:268
程序員0基礎該怎麼學 瀏覽:276
android支付寶支付原理 瀏覽:729
股票指標加密可以導入 瀏覽:935
怎樣演算法排卵期 瀏覽:803
小米如何加密第三方軟體 瀏覽:232