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 回答
![?](http://img1.sycdn.imooc.com/533e4c9c0001975102200220-100-100.jpg)
千万里不及你
TA贡献1784条经验 获得超9个赞
从技术上讲,您可以使用自定义视图以编程方式应用样式:
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 关注
- 353 浏览
添加回答
举报
0/150
提交
取消