【问题标题】:Text color isn't ligth in Material Theme Light.DarkActionBarMaterial Theme Light.DarkActionBar 中的文本颜色不亮
【发布时间】:2016-09-27 20:38:55
【问题描述】:

我正在尝试使用 Material Design Light.DarkActionBar 主题自定义 App 主题,但 actionBar 中的文本颜色为黑色。我尝试使用 textColorPrimary 将颜色更改为白色,但是当我这样做时,我的应用程序中的所有文本都更改为白色。

这是我的价值观/风格:

    <resources>
  <!-- Inherit from the light Material Theme -->
  <style name="MissaoCaronaTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimaryDark">@color/amareloSecundario</item>
    <!-- cor da barra -->
    <item name="colorPrimary">@color/amareloPrimario</item>
    <!-- Cor dos controles -->
    <item name="colorAccent">@color/amareloPrimario</item>
  </style>

</resources>

这是我的价值观-v21/styles:

<resources>
  <style name="MissaoCaronaTheme" parent="@android:style/Theme.Material.Light.DarkActionBar">
    <item name="android:colorPrimaryDark">@color/amareloSecundario</item>
    <!-- cor da barra -->
    <item name="android:colorPrimary">@color/amareloPrimario</item>
    <!-- Cor dos controles -->
    <item name="android:colorAccent">@color/amareloPrimario</item>
  </style>
</resources>

这是我的 androidmanifest:

<application android:label="@string/ApplicationName" android:theme="@style/MissaoCaronaTheme"></application>

这是我的布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="40dp"
        local:MvxBind="Text Hello" />
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="40dp"
        local:MvxBind="Text Hello" />
</LinearLayout>

这是我的活动:

[Activity(Label = "Usuário")]
    public class UsuarioEditView : MvxActivity<UsuarioViewModel>
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.UsuarioEditView);
        }
    }

【问题讨论】:

    标签: android xamarin.android material-design mvvmcross android-styles


    【解决方案1】:

    请按照代码为活动标签部分初始化您的主题。

    [Activity(Label = "Usuário", Theme = "@style/MissaoCaronaTheme", Icon = "@drawable/icon")]

    【讨论】:

      【解决方案2】:

      维尼修斯,

      您可以为 actionBar 中的文本创建特定样式,并将其仅用于此文本,而不是更改 textColorPrimary。

      例如:

      在styles.xml中:

      <item name="colorTextActionBar">@color/branco</item>
      

      在这种情况下,还要编辑 color.xml 文件:

      <item name="branco" type="color">#FFFFFFFF</item>
      

      【讨论】:

      • 没用。我收到一条消息“找不到与“colorTextActionBar”匹配的资源
      • Vinícius,请发布您的活动资源文件。
      • 好的,我的回答具有误导性。试试这个:stackoverflow.com/questions/8024706/…
      • 但是,不要像上面的链接那样更改“android:background”,而是尝试“android:textColorPrimary”。
      【解决方案3】:

      因此,当您更改 textColorPrimary 时,它将影响整个应用程序主题,这意味着与此样式关联的所有组件都会受到影响。这就是为什么你所有的文字都变成了白色。 因此,您可以添加您选择的新颜色,而不是更改常用颜色。 您还需要确保在您的 colors.xml 文件中添加相应的颜色。

      在styles.xml 中:

      <item name:"nameOfYourChoice">@color/colorName</item>
      

      在 colors.xml 中:

      <color name="colorName">#colorValue</color>
      

      确保正确编辑 xml 文件。

      【讨论】:

        【解决方案4】:

        我发现了问题。问题是来自 MvvmCross 框架的 MvxActivity。我不知道为什么,但是当我将 MvxActivity 与 Material Design 一起使用时,ActionBar 的文本总是为黑色,而当我将 MvxAppCompatActivity 与 AppCompat 主题一起使用时,AcioBar 的标题是白色的。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2022-10-25
          • 1970-01-01
          • 2015-01-08
          • 1970-01-01
          • 2022-12-04
          • 2023-03-22
          • 1970-01-01
          • 2019-05-21
          相关资源
          最近更新 更多