我使用一些按鈕以編程方式爲AlertDialog創建LinearLayout。Android - 如何以編程方式設置Linearlayout中的按鈕樣式?
我WANT做到這一點:
<LinearLayout android:id="@+id/footer" android:layout_width="fill_parent"
style="@android:style/ButtonBar">
但隨着這樣的代碼:programmitically
LinearLayout buttons = new LinearLayout(parentContext);
buttons.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams buttonsParams =
new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
topLayout.addView(buttons, buttonsParams);
buttons.setLayoutParams(buttonsParams);
Button btnAdd = new Button(context);
btnAdd.setText("Add");
我如何設置按鈕的樣式(使用一個按鈕欄)?
不幸的是它是不可能的。您只能以編程方式向文本範圍添加樣式。 – 2012-07-10 21:28:42
也許這可能有所幫助:http://stackoverflow.com/questions/2016249/how-to-programmatically-setting-style-attribute-in-a-view – 0gravity 2012-07-10 21:29:25
不工作 http://stackoverflow.com/ questions/3142067/android-set-style-in-code – user1365315 2013-03-14 01:59:43