【问题标题】:Xamarin Android with appcompat makes all my text white带有 appcompat 的 Xamarin Android 使我的所有文本变为白色
【发布时间】:2016-05-08 20:41:10
【问题描述】:

我正在尝试为我的 Xamarin Android 应用了解和实现 Material Theme。我已经阅读了this blog postthe Android documentation 等资源。但我想我仍然错过了一些重要的东西。

简而言之:我已将父主题设置为“Theme.AppCompat.Light.DarkActionBar”。并且所有文本(textview)都是白色的。而且我想尽可能地遵守 Material Design 指南。

values/styles.xml

  <style name="MyTheme" parent="MyTheme.Base">
  </style>

  <style name="MyTheme.Base" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="android:windowNoTitle">true</item>
    <!--We will be using the toolbar so no need to show ActionBar-->
    <item name="android:windowActionBar">false</item>
  </style>

values-v21

  <style name="MyTheme" parent="MyTheme.Base">
    <item name="android:windowContentTransitions">true</item>
    <item name="android:windowAllowEnterTransitionOverlap">true</item>
    <item name="android:windowAllowReturnTransitionOverlap">true</item>
    <item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
    <item name="android:windowSharedElementExitTransition">@android:transition/move</item>
  </style>

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="MaterialDesignTest1.MaterialDesignTest1" android:versionCode="1" android:versionName="1.0">
    <uses-sdk android:targetSdkVersion="22" android:minSdkVersion="21" />
    <application android:label="MaterialDesignTest1"  android:theme="@style/MyTheme"></application>
</manifest>

Mainactivity.cs

[Activity(Label = "MaterialDesignTest1", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : FragmentActivity
{
    /* Omitted the viewpager & tablayout code */
}

还有我正在加载到选项卡中的 FilmsFragment.axml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:text="Fragment that shows all Starwars Films information 1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="30dp" />
</LinearLayout>

结果如附图所示:

当我将父级更改为 parent="@style/Theme.AppCompat.Light"parent="Theme.AppCompat.Light" 时:

将 SDK Target 设置为 23 有点变化,但仍然是白色字体:

什么属性赋予所有字体白色?为什么?

Xamarin:4.0.0.1717

Xamarin Android:6.0.0.35

所有 Xamarin 支持包:23.1.1.0

【问题讨论】:

    标签: android xamarin material-design


    【解决方案1】:

    如果您想为您的应用设置特定颜色,请确保在您的 MyTheme.Base 中添加

       <!-- Main theme colors -->
        <!--   your app branding color for the app bar -->
        <item name="android:colorPrimary">@color/primary</item>
        <!--   darker variant for the status bar and contextual app bars -->
        <item name="android:colorPrimaryDark">@color/primary_dark</item>
        <!--   theme UI controls like checkboxes and text fields -->
        <item name="android:colorAccent">@color/accent</item>
    

    您也应该使用 AppCompatActivity 而不是 FragmentAcitivty。

    【讨论】:

      猜你喜欢
      • 2017-03-06
      • 1970-01-01
      • 2021-10-29
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-18
      相关资源
      最近更新 更多