【问题标题】:textview color got changed after changing the theame to app compat将主题更改为 appcompat 后,textview 颜色发生了变化
【发布时间】:2014-11-21 14:08:03
【问题描述】:

我正在尝试升级我的应用程序以支持棒棒糖前设备上的材料设计,为此我添加了 android 支持库 v7 并将我的应用程序的样式从 android:Theme.Holo.Light.DarkActionBar 更改为 Theme.AppCompat.NoActionBar。现在我的 MainActivity 扩展了支持库的 ActionBarActivity 以及这个我已经将我的操作栏更改为工具栏。

直到这里一切正常,它显示了带有动画的新抽屉切换图标,但在我的整个应用程序中,所有文本颜色已从 Black 更改为 White现在我不知道我必须从哪里改变。我必须在每个布局中更改它吗?

我正在使用具有以下配置的 Android Studio。

Build.gradle

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
}
dependencies {
    compile "com.android.support:appcompat-v7:21.0.+"

}

Style.xml

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>

<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
    <item name="spinBars">false</item>
</style>

Layout.xml

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

    <LinearLayout
        android:id="@+id/layout"
        style="@style/Default"
        android:orientation="vertical">

        <TextView
            android:id="@+id/name_label"
            style="@style/SectionHeader.First"
            android:text="@string/name"/>

        <TextView
            android:id="@+id/name"
            style="@style/Text.SingleLine" />

        <TextView
            android:id="@+id/email_label"
            style="@style/SectionHeader"
            android:text="@string/email" />

        <TextView
            android:id="@+id/email"
            style="@style/Text.SingleLine" />

        <TextView
            android:id="@+id/app_version_label"
            style="@style/SectionHeader"
            android:text="@string/app_version" />

        <TextView
            android:id="@+id/app_version"
            style="@style/Text.SingleLine" />

        <TextView
            android:id="@+id/customer_support_label"
            style="@style/SectionHeader"
            android:visibility="gone"
            android:text="@string/customer_support" />

        <TextView
            android:id="@+id/customer_support_phone"
            style="@style/Text.SingleLine"
            android:visibility="gone"
            android:autoLink="all" />
        <TextView
            android:id="@+id/customer_support_email"
            style="@style/Text.SingleLine"
            android:visibility="gone"
            android:autoLink="all" />

        <Switch
            android:id="@+id/alarm_service_toggle"
            android:layout_marginTop="@dimen/small_padding"
            style="@style/Default" />

        <TextView
            style="@style/Text.SingleLine"
            android:textColor="@android:color/tertiary_text_light"
            android:text="@string/switch_location_sub_message" />

        <Button
            android:id="@+id/capture_logs"
            style="@style/Default"
            android:layout_marginTop="@dimen/medium_padding"
            android:text="@string/capture_logs" />

        <Button
            android:id="@+id/logout"
            style="@style/Default"
            android:layout_marginTop="@dimen/medium_padding"
            android:text="@string/logout" />
    </LinearLayout>
</ScrollView>

如果需要我提供任何其他输入,请告诉我。

【问题讨论】:

    标签: android textview material-design


    【解决方案1】:

    使用Theme.AppCompat.Light.NoActionBar 代替Theme.AppCompat.NoActionBar

    【讨论】:

      【解决方案2】:

      在主题中你必须定义文本颜色

         SetTextColor(Color.colorname); 
      

      在运行时来自 java

      在xml android:textColor="#color code"

      【讨论】:

      • 所以你是想说现在默认颜色是白色而不是黑色,我必须更改所有布局?
      • 你需要在你的主题中改变颜色 或试试这个链接stackoverflow.com/questions/13142098/…
      • 感谢您的回复。您的答案是已接受答案的替代方案,因此您也可以为您的答案 +1。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-27
      • 1970-01-01
      • 1970-01-01
      • 2020-04-01
      • 2011-03-11
      • 1970-01-01
      相关资源
      最近更新 更多