android - 当 Api 级别为 24 时,文本颜色在 xml 中不起作用

标签 android xml android-layout textcolor android-7.0-nougat

我面临一个基本问题,当我设置 api 级别 24 时,TextViewButton 的文本颜色没有从 xml 改变。它显示颜色改变了预览但不是当应用程序安装在设备上时,我还没有找到任何解决方案,即使我不知道它为什么会发生,这是我的 xml 文件。

<LinearLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:clickable="true"
    android:focusable="false"
    android:id="@+id/dragView"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/bottom_height"
        android:background="@color/bottom_grey_color"
        android:paddingRight="@dimen/bottom_margin"
        android:paddingLeft="@dimen/bottom_margin"
        >

        <include layout="@layout/cart_layout"
            ></include>


        <TextView
            android:id="@+id/tvTotalPrice"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:textSize="14sp"
            android:text="Rs: 20898789"
            android:gravity="center_vertical"
            android:textColor="@color/white"

            android:layout_toRightOf="@+id/cart_layout"
            android:paddingLeft="10dp"/>

        <ImageView
            android:layout_width="40dp"
            android:layout_height="30dp"
            android:layout_centerHorizontal="true"
            android:src="@mipmap/bottom_bar"
            />

        <Button
            android:id="@+id/btnCheckout"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:textSize="14sp"
            android:gravity="center_vertical|right"
            android:text="Check Out"
            android:textColor="@color/app_color"
            android:layout_alignParentRight="true"
            android:background="@color/white"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            />

    </RelativeLayout>
    <android.support.v7.widget.RecyclerView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
    </android.support.v7.widget.RecyclerView>

</LinearLayout>

这是 Gradle 文件..

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"
    defaultConfig {
        applicationId "com.xxxxxxx"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                cppFlags "-frtti -fexceptions"
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.android.support:appcompat-v7:24.0.0-alpha1'
    compile 'com.sothree.slidinguppanel:library:3.3.1'
    compile 'com.android.support:design:24.0.0-alpha1'
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.squareup.okhttp:okhttp:2.5.0'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.android.support:support-v4:24.0.0-alpha1'
    testCompile 'junit:junit:4.12'
}

这是样式文件..

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

颜色文件...

<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
    <color name="white">#ffffff</color>
    <color name="black">#000000</color>
    <color name="bottom_grey_color">#b5b5b5</color>
    <color name="app_color">#2e318e</color>
    <color name="bg_color">#ebebeb</color>
    <color name="cart_bg_color">#da0000</color>
</resources>

list 代码..

    <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".Activity.MainActivity"
        android:label="@string/app_name"
        android:launchMode="singleTop"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
        </intent-filter>
    </activity>
</application>

输出: enter image description here

最佳答案

也许您有 values-v21 文件夹并且文本颜色为白色(或未更改)。检查一下,让我知道。我遇到了同样的问题,但通过这种方式解决了。

关于android - 当 Api 级别为 24 时,文本颜色在 xml 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39828766/

相关文章:

android - 如何在单击时更改图像按钮

Android:如何将捕获的图像保存到特定文件夹

java - 无法通过 JADE 在 android 中接收 ACLMessage

android - 从外部文件中读取 android URL

php - PHP 中的容错 HTML/XML/SGML 解析

android - <include> 标签覆盖属性

android - Restcomm android sdk 与其他 sip 服务器

android - 以全长创建 RecyclerView 的 PDF

xml - 根据内容选择子节点

java - ImageView 上的透明背景 EditText 不会显示光标