相关疑难解决方法(0)

覆盖引用的样式属性

阅读参考主题属性后,我试图在我设置的自定义主题中引用属性的值.

我将用户定义的样式应用于 CheckedTextView

<CheckedTextView
    android:id="@+id/contactInfo"
    style="@style/ListViewCheckedTextViewRowStyle" >
</CheckedTextView>
Run Code Online (Sandbox Code Playgroud)

用户定义的样式定义为:

<style name="ListViewCheckedTextViewRowStyle" parent="@style/ListViewRowStyle">
    <item name="android:checkMark">?android:listChoiceIndicatorMultiple</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我创建的主题定义为:

<style name="Theme.Yellowgreen" parent="android:Theme.Holo.Light.DarkActionBar">
    <item name="android:listChoiceIndicatorMultiple">@drawable/btn_check_holo_light</item>
</style>
Run Code Online (Sandbox Code Playgroud)

但是,显示的checkMark样式是设备的默认主题的drawable,而不是我的用户定义的drawable.

我可以显示可绘制的唯一方法是:

<style name="ListViewCheckedTextViewRowStyle" parent="@style/ListViewRowStyle">
    <item name="android:checkMark">@drawable/btn_check_holo_light</item>
</style>
Run Code Online (Sandbox Code Playgroud)

但这违背了覆盖此属性的整个目的,特别是因为我想在多个主题中覆盖此属性.

我在onCreate()我的方法中设置主题Activity:

public void onCreate(Bundle savedInstanceState) {
    this.setTheme(R.style.Theme_Yellowgreen);
    super.onCreate(savedInstanceState);
    // ...
}
Run Code Online (Sandbox Code Playgroud)

我还尝试在AndroidManifest.xml文件中设置主题,如:

<application android:theme="@style/Theme.Yellowgreen" >
Run Code Online (Sandbox Code Playgroud)

但那没用.怎么可能出错?

更新

我刚刚创建了一个小型示例项目,看起来我上面发布的代码正在运行.所以我必须有一些其他样式覆盖这个属性,或者它可能与我的布局xml文件有关.

在我的大项目中,我有两个FragmentsActivity.两者Fragments都有Listviews支持Adapters.在Fragment A所述getView()的方法Adapter如下:

public View getView(final int position, View convertView, …
Run Code Online (Sandbox Code Playgroud)

android themes styles overriding checkedtextview

9
推荐指数
1
解决办法
3万
查看次数

标签 统计

android ×1

checkedtextview ×1

overriding ×1

styles ×1

themes ×1