導航:首頁 > 操作系統 > android動態添加button

android動態添加button

發布時間:2022-09-19 16:20:49

Ⅰ 請問在android的listView中怎麼動態加入radioButton和Button按鈕

RadioButton radio1 = new RadioButton(ProxyGetQueueCodeActivity.this);//ProxyGetQueueCodeActivity類名
radio1.setTextSize(20.0f);
radio1.setTextColor(Color.BLUE);
radio1.setText("顯示文字");
rg_proxy_biztype.addView(radio1);//rg_proxy_biztype是定義的listView名字。。。。。
Button也差不多

Ⅱ android動態添加按鈕並保存設置,再次進入程序時能直接操作第一次添加保存的按鈕

在代碼中動態創建一個button2(Button button2 = new Button(this)),然後把button2添加的你的布局中,比如你的布局是線性布局的話,linearlayout.addView(button2);然後需要SharedPreferences來保存button2可見的這個屬性值,設置button2的可見屬性,第一次默認為隱藏,button2.setVisibility(View.GONE),然後在button1設置它的點擊事件,當點擊後,修改button2的可見屬性,並修改SharedPreferences里的屬性值,這樣,每次你進入程序後,先讀SharedPreferences里的設置,來判斷是否顯示button2,然後你可以通過點擊button1,來修改button2是否可見的屬性,來達到點擊button1創建一個button2的目的。

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

可以。

1、通過id獲取button組件

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

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

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

Ⅳ android 我寫了幾個動態的Button!我想把這個button添加到靜態布局文件裡面!怎麼實現啊

試試把靜態的布局文件加上ID,然後在代碼里實現它,再用add方法,把動態Button添加到裡面。

Ⅳ android 動態添加button並設置選中

Button 沒有選中和不選中的狀態,如果要選中或者不選中,要使用Android提供的RadioGroup+RadioButton 或者使用CheckBox這些控制項。
RadioGroup+RadioButton Android會自動的選中,只會有一個選中。
CheckBox需要寫狀態去控制。

Ⅵ 用Android開發,在代碼中動態生成Button按鈕,能設置這個按鈕的坐標嗎,怎麼設置呢

設置按鈕坐標,需要上一層是絕對布局,然後在用 button.setLayoutParams(params);設置button出現的位置

Ⅶ 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相關的資料

熱點內容
魔獸辛迪加是什麼伺服器 瀏覽:471
電腦文件夾排序怎麼自定義排序 瀏覽:41
android70機型 瀏覽:422
阿里程序員地位 瀏覽:183
js如何上傳大文件到伺服器地址 瀏覽:685
安卓系統2個卡怎麼切換 瀏覽:182
vivoy9s手機怎麼設置隱私相冊加密 瀏覽:158
android載入網路數據 瀏覽:119
tc語言入門編程 瀏覽:339
載入器app源碼大全 瀏覽:821
linux刷新hosts 瀏覽:620
cmd命令鍵盤 瀏覽:311
優盤空文件夾怎麼刪不掉 瀏覽:843
androidsetpixels 瀏覽:909
掃碼輔助接單平台源碼 瀏覽:781
uc2雲平台伺服器 瀏覽:825
蘋果桌面的文件夾可以變顏色嗎 瀏覽:537
pdf定義域 瀏覽:448
怎樣壓縮圖片到最小 瀏覽:260
app券商怎麼做 瀏覽:179