Android:以編程方式設置視圖樣式這是XML:<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/LightStyle"
android:layout_width="fill_parent"
android:layout_height="55dip"
android:clickable="true"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" /></RelativeLayout>如何以style編程方式設置屬性?
3 回答

慕妹3242003
TA貢獻1824條經驗 獲得超6個贊
從技術上講,您可以使用自定義視圖以編程方式應用樣式:
private MyRelativeLayout extends RelativeLayout { public MyRelativeLayout(Context context) { super(context, null, R.style.LightStyle); }}
一個參數構造函數是以編程方式實例化視圖時使用的構造函數。
因此,將此構造函數鏈接到帶有樣式參數的super。
RelativeLayout someLayout = new MyRelativeLayout(new ContextThemeWrapper(this,R.style.RadioButton));
或者@Dori指出:
RelativeLayout someLayout = new RelativeLayout(new ContextThemeWrapper(activity,R.style.LightStyle));
- 3 回答
- 0 關注
- 449 瀏覽
添加回答
舉報
0/150
提交
取消