
我想为Android小部件定义不同的可用样式.在下面的示例中,有两个ImageVIEw小部件,其中一个使用我的“主题”样式,另一个使用manualy样式.我希望以我coluld省略’base_theme’前缀的方式实现配置文件,以便可以根据活动主题配置自动确定.
有关编写主题的文档提到了如何更改所有ImageVIEw或按钮的样式,而不是具有样式属性的特定样式.我发现可以通过使用可设置样式的自定义组件来解决我的问题,但我认为有一些更好的方法来解决我的问题.
base_style.xml
<style name="base_theme" parent="androID:theme.NoTitlebar"></style><style name="base_theme.event_List_filter"> <item name="androID:orIEntation">horizontal</item> <item name="androID:layout_wIDth">fill_parent</item> <item name="androID:layout_height">wrap_content</item> <item name="androID:layout_margin">10dp</item> <item name="androID:background">@drawable/base_white_rounded</item></style><style name="base_theme.base_event_List_filter_image"> <item name="androID:layout_wIDth">wrap_content</item> <item name="androID:layout_height">wrap_content</item> <item name="androID:padding">10dp</item> <item name="androID:background">@drawable/vr_black_border</item></style><style name="base_theme.base_event_List_scrollable"> <item name="androID:layout_wIDth">fill_parent</item> <item name="androID:layout_height">0dp</item> <item name="androID:layout_weight">1</item> <item name="androID:background">@drawable/base_white_rounded</item></style><style name="base_theme.base_event_List_table"> <item name="androID:layout_wIDth">fill_parent</item> <item name="androID:layout_height">fill_parent</item></style>activity_layout.xml
<linearLayout > <ImageVIEw androID:src="@drawable/pic0" /> <ImageVIEw ... androID:src="@drawable/pic1" /></linearLayout>感谢帮助,
MacIEk
解决方法:
我找到了解决方案.我希望它能帮助那些有类似主题问题的人.
首先,我已经为我的base_theme添加了新属性,然后我按照以下方式配置它们:
base_style.xml
<?xml version="1.0" enCoding="utf-8"?><resources> <!-- add attributes to your theme -->s <declare-styleable name="base_theme"> <attr name="event_List_filter" format="reference" /> <attr name="pic0" format="reference" /> </declare-styleable> <!-- fill attributes with your own styles/drawables/etc --> <style name="base_theme" parent="androID:theme.NoTitlebar"> <item name="event_List_filter">@style/base_theme.event_List_filter_image</item> <item name="pic0">@drawable/base_theme.pic0</item> </style> <!-- define corresponding resource --> <style name="base_theme.base_event_List_filter_image"> <item name="androID:layout_wIDth">wrap_content</item> <item name="androID:layout_height">wrap_content</item> <item name="androID:padding">10dp</item> <item name="androID:background">@drawable/vr_black_border</item> </style> <drawable name="base_theme.pic0">@drawable/base_pic0</drawable></resources>另一个布局是steel_styles.xml
<?xml version="1.0" enCoding="utf-8"?><resources> <!-- fill attributes with your own styles/drawables/etc --> <style name="steel_theme" parent="@style/base_theme"> <item name="pic0">@drawable/steel_theme.pic0</item> </style> <drawable name="steel_theme.pic0">@drawable/steel_pic0</drawable></resources>活动布局文件activity_layout.xml
...<ImageVIEw androID:src="?attr/pic0" />...通过这样的配置,pic0将根据AndroIDManifest.xml中的活动主题设置在屏幕上不同.
总结以上是内存溢出为你收集整理的android – 将不同的可变样式定义为相同的小部件类型全部内容,希望文章能够帮你解决android – 将不同的可变样式定义为相同的小部件类型所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)