android - 为什么我的自定义主题不影响我的自定义列表项布局的 TextView ?

标签 android android-layout android-theme

我正在尝试使用自定义主题来管理我的应用程序样式:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="Theme.Styled" parent="Theme.Sherlock.Light.DarkActionBar">
        <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
        <item name="actionBarTabStyle">@style/Widget.Sherlock.Light.ActionBar.TabView</item>
        <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>
        <item name="android:textViewStyle">@style/MyTextViewStyle</item>
    </style>

    <style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
        <item name="background">@drawable/background</item>
        <item name="android:background">@drawable/background</item>
    </style>

    <style name="MyTextViewStyle" parent="@android:style/Widget.TextView">
        <item name="android:textColor">@color/text</item>
    </style>

</resources>

如您所见,我将 TextView 默认颜色设置为@color/text (#ff000000)。这在我的应用程序的所有 TextView 中都可以正常工作,但我的自定义列表项布局中的除外:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/mov_concept"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="2dp"
        android:textSize="16dp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/mov_category"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/mov_concept"
        android:layout_marginLeft="5dp"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/mov_amount"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/mov_category"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="6dp"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/mov_period"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/mov_amount"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="5dp"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/mov_until"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/mov_period"
        android:layout_alignBottom="@+id/mov_period"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="2dp"
        android:layout_marginRight="5dp"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/mov_date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/mov_concept"
        android:layout_alignBottom="@+id/mov_category"
        android:layout_alignParentRight="true"
        android:layout_marginRight="5dp"
        android:layout_marginTop="2dp" />

</RelativeLayout>

我不知道为什么会这样,提前谢谢你。

最佳答案

我遇到了同样的问题,因为使用 Application Context 而不是 ListAdapter 的 Activity Context。为了解决这个问题,我更改了我的代码

MyAdapter adapter = new MyAdapter(getApplicationContext(), ...) 

MyAdapter adapter = new MyAdapter(MyActivity.this, ...)

关于android - 为什么我的自定义主题不影响我的自定义列表项布局的 TextView ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12342924/

相关文章:

android-layout - 重用具有多种背景颜色的边框资源

android - 如何从 jetpack compose 更改 OutlinedTextField 的轮廓颜色?

Android应用程序-检测应用程序推送通知是否关闭

android - 我如何在没有网站的情况下注册 AdMob?

java - 如何在底部导航 fragment (或抽屉导航)之间传递数据?

android - 如何让动画效果在 Activity 之间持续存在?

Android sqlite 更新问题

android - Android 手机和平板电脑上同一屏幕的 PercentRelativeLayout?

android - 带有 Theme.Material 的平面操作栏

android - 启动画面仅在 Android 8.1 上触发 Resources$NotFoundException