我想以编程方式执行此操作:
<ImageView style="@style/TitleBarSeparator" />
Where TitleBarSeparator
is:
<style name="TitleBarSeparator">
<item name="android:layout_width">1px</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:background">@color/title_separator</item>
</style>
我试过了:
new ImageView(getContext(), null, R.style.TitleBarSeparator);
但它不起作用。
我猜错误来自于将 null 传递为AttributeSet
但我不完全确定。
我找到了修复它的方法。
View v = new ImageView(getContext());
v.setLayoutParams(new LayoutParams(1, LayoutParams.FILL_PARENT));
v.setBackgroundColor(getContext().getResources().getColor(R.color.title_separator));
尽管如此,我还是希望有一种方法来设置样式。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)