无法覆盖主题默认文本颜色(安卓)

3

我希望只有一个列表视图,而不是主题的默认颜色,使用不同的文本颜色。我可以覆盖文本大小、样式和行背景颜色,但文本颜色仍然是主题的默认值。有人能告诉我我做错了什么吗?这是我的styles.xml:

<resources>

<!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->

</style>

<style name="rowstyle" parent="@style/rowbackground">
   <item name="android:textColor">#FFFFFF</item>
   <item name="android:textSize">25sp</item>
   <item name="android:textStyle">bold</item>
</style>

<style name="rowbackground" >
   <item name="android:background">@drawable/row_background</item>
   <item name="android:paddingLeft">15dp</item>
</style>

</resources>  

以下是activity_main.xml的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.houstone.MainActivity" >

<ListView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_centerHorizontal="true"
  android:layout_below="@+id/countries"      
  android:id="@+id/cities"
  style="@style/rowstyle"/>
</RelativeLayout>

请添加适配器代码。 - Sanjay Kakadiya
1个回答

1
我自己也遇到了这个问题。解决方法是在ListView中设置android:theme而不是style,就像OP所做的那样。

为了通过编程方式创建实例,您可能想要使用ContextThemeWrapper类,例如以下代码:val builder = AlertDialog.Builder(ContextThemeWrapper(context, R.style.YourOwnStyle)) - longi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接