Xamarin Android添加按钮文本全部大写 - 如何在整个应用程序中应用样式?

时间:2015-05-07 13:17:10

标签: android xamarin android-styles

我是移动开发的新手,我正在使用Xamarin工作室开发一个简单的应用程序,并在我的页面上添加了几个按钮。我注意到当我在模拟器(Android 5.0.1 - API 21)中运行时,所有按钮文本都出现在CAPITAL LETTERS中。

我已经关注Why is my Button text forced to ALL CAPS on Lollipop?并尝试在我的style.xml中添加<item name="android:textAllCaps">false</item>,但它没有任何区别。

同时选中Why is my Button text forced to ALL CAPS on Lollipop?Android 5.0 (Lollipop) widget button's text are in ALL CAPS

如果我将android:textAllCaps = "false"添加到我的所有按钮(在我的axml文件中),那么它将起作用,但我想知道应用程序中所有按钮的通用样式(甚至在多种形式/活动中)

有人可以建议一种在整个应用程序中使用某种风格的方法吗?

谢谢。

1 个答案:

答案 0 :(得分:14)

您可以尝试在Resources / values文件夹中将以下内容添加为styles.xml。

<?xml version="1.0" encoding="UTF-8" ?>
<resources>
  <!-- Inherit from the light Material Theme -->
  <style name="MyCustomTheme" parent="android:Theme.Material">
    <!-- Customizations go here -->
    <item name="android:textAllCaps">false</item>
  </style>
</resources>

然后在您的MainActivity.cs中,应用此自定义主题

[Activity(Label = "MyActivity", Theme = "@style/MyCustomTheme")]