Android的textAllCaps的主题 [英] Android textAllCaps in Theme

查看:916
本文介绍了Android的textAllCaps的主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主题,其中就想上活动的所有textviews资本化。所以我设置的风格textAllCaps,然后在我的主题,如把它应用到textViewStyle低于

I have a theme where on wanted all textviews on activities to be capitalized. So I set textAllCaps in a style and then applied it to textViewStyle in my theme like the below

<style name="Widget.Apex.TextView" parent="android:Widget.TextView">
  <item name="android:textAppearance">?android:attr/textAppearanceSmall</item>
  <item name="android:textAllCaps">true</item>
</style>

<style name="MyTheme" parent="@android:style/Theme.Holo">
  <item name="android:textViewStyle">@style/Widget.Apex.TextView</item>
</style>

可惜这不得不把我的应用程序标题,字幕的ActionBar的副作用,popmenu项目资本化。所以我想,我只想设置ActionBarStyle,textAppearanceLargePopupMenu和textAppearanceSmallPopupMenu在我的主题属性与textAllCaps = false一个自定义样式。但是,这是行不通的。我知道我的主题被应用,因为如果我设置文字颜色或TEXTSTYLE它们都适用于标题和菜单项。是否有可能重写textAllCaps这些样式?

Unfortunately this had the side effect of turning my Application Title, ActionBar subtitles, and popmenu items capitalized. So I thought I would just set the ActionBarStyle, textAppearanceLargePopupMenu, and textAppearanceSmallPopupMenu attributes in my theme to have a custom style with textAllCaps=false. However, this does not work. I know my themes are being applied because if I set textColor or textStyle they are both applied to the titles and menu items. Is it possible to override the textAllCaps in these styles?

<style name="Widget.Apex.TextView" parent="android:Widget.TextView">
  <item name="android:textAppearance">?android:attr/textAppearanceSmall</item>
  <item name="android:textAllCaps">true</item>
</style>
<style name="TextAppearance.Apex.Widget.ActionBar.Title" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
  <item name="android:textAllCaps">false</item>
  <item name="android:textStyle">italic</item>
</style>
<style name="TextAppearance.Apex.Widget.ActionBar.Subtitle" parent="android:TextAppearance.Holo.Widget.ActionBar.Subtitle">
  <item name="android:textAllCaps">false</item>
  <item name="android:textStyle">italic</item>
  <item name="android:textColor">#FF0000</item>
</style>
<style name="TextAppearance.Apex.Widget.PopupMenu.Large" parent="android:TextAppearance.Holo.Widget.PopupMenu.Large">
  <item name="android:textAllCaps">false</item>
  <item name="android:textStyle">italic</item>
  <item name="android:textColor">#FF0000</item>
</style>
<style name="TextAppearance.Apex.Widget.PopupMenu.Small" parent="android:TextAppearance.Holo.Widget.PopupMenu.Small">
  <item name="android:textAllCaps">false</item>
  <item name="android:textStyle">italic</item>
  <item name="android:textColor">#FF0000</item>
</style>
<style name="Widget.Apex.ActionBar" parent="android:Widget.Holo.ActionBar">
  <item name="android:titleTextStyle">@style/TextAppearance.Apex.Widget.ActionBar.Title</item>
  <item name="android:subtitleTextStyle">@style/TextAppearance.Apex.Widget.ActionBar.Subtitle</item>
</style>

<style name="MyTheme" parent="@android:style/Theme.Holo">
  <item name="android:actionBarStyle">@style/Widget.Apex.ActionBar</item>
  <item name="android:textAppearanceLargePopupMenu">@style/TextAppearance.Apex.Widget.PopupMenu.Large</item>
  <item name="android:textAppearanceSmallPopupMenu">@style/TextAppearance.Apex.Widget.PopupMenu.Small</item>
  <item name="android:textViewStyle">@style/Widget.Apex.TextView</item>
</style>

谢谢,
乔纳森

Thanks, Jonathan

推荐答案

使用的应用程序兼容性 textAllCaps Android应用支持旧的API的(小于14)

By using AppCompat textAllCaps in Android Apps supporting older API's (less than 14)

一个对这项工作各地将明确设置的风格是这样的:

A work around for this would to explicitly set the style like this:

<android.support.v7.internal.widget.CompatTextView
        style="@style/MyTextViewStyle"
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:textAllCaps="true"/>

或选择使用新的风格,继承了textViewStyle,并增加了textAllCaps以及任何其他样式您选择的属性:

or alternatively use a new style that inherits textViewStyle and adds the textAllCaps attribute along with any other styles of your choosing:

  <style name="MyCompatTextViewStyle" parent="MyTextViewStyle">
            <item name="textAllCaps">true</item>
        </style>

在布局:

<android.support.v7.internal.widget.CompatTextView
            style="@style/MyCompatTextViewStyle"
            android:id="@+id/text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

请注意:

1>这个小部件不会继承了在你的主题通过的android:textViewStyle

1> this widget won't inherit any default styles that are set in your theme via android:textViewStyle

2>使用这个小部件似乎给包名字,意思是它不是真正用于公共API是内部的。它也没有在该 textAllCaps 属性需要直接对风格/视图,并不能在textAppearance风格为它工作完全成熟。

2>Using this widget seems to be internal given the package name meaning it's not really intended for public API. It's also not "fully baked" in that the textAllCaps attribute needs to be directly on the style/view and can not be in the textAppearance style for it to work.

这篇关于Android的textAllCaps的主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆