使用"安卓textAppearance"在TextView中/ EditText上会失败,但和QUOT;样式"作品 [英] Using "android:textAppearance" on TextView/EditText fails, but "style" works

查看:130
本文介绍了使用"安卓textAppearance"在TextView中/ EditText上会失败,但和QUOT;样式"作品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个XML格式的样品TextView的,这将样式 TextContactContactName 正确应用到TextView的。

This is a sample TextView in XML, which will properly apply the style TextContactContactName to the TextView.

<TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/photo"
        android:layout_alignTop="@id/photo"
        android:paddingLeft="10dp"
        android:text="First Last"
        style="@style/TextContactContactName"
        />

现在,我有一些其他的东西,这个元素上设置,这是不相关的文字。因此我试图移动 TextContactContactName ,并通过应用它的Android:textAppearance

Now, I have some other things to set on this element, which are not text related. As such I tried to move the TextContactContactName and apply it via "android:textAppearance"

<TextView
    android:id="@+id/name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/photo"
    android:layout_alignTop="@id/photo"
    android:paddingLeft="10dp"
    android:text="First Last"
    android:textAppearance=@style/TextContactContactName"
    />

然而好景不长,文本格式不被应用。

Unluckily, the text formatting is not being applied.

这是怎样的风格(存储在 RES /价值/风格-text.xml )是这样的:

This is how the style (stored in res/values/styles-text.xml) looks like:

<style name="TextContactContactName">
    <item name="android:textSize">24sp</item>
    <item name="android:textColor">#333333</item>
    <item name="android:shadowColor">#ffffff</item>
    <item name="android:shadowDx">0</item>
    <item name="android:shadowDy">1</item>
    <item name="android:shadowRadius">1</item>
</style>

我使用了 textAppearance 标记错了吗?

我测试了在Android 2.2 - HTC Desire的

I tested on Android 2.2 - HTC Desire.

推荐答案

好吧,看起来像我的错。我做了一个简单的测试:

Ok, looks like my fault. I had made a quick test:

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Text styled using 'style'."
        style="@style/UiTestTextView"
        />
<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Text styled using 'textAppearance'."
        android:textAppearance="@style/UiTestTextView"
        />

和样式,text.xml:

and the styles-text.xml:

<style name="UiTestTextView">
    <item name="android:textColor">#ff0000</item>
    <item name="android:textSize">16sp</item>

    <item name="android:shadowColor">#ffffff</item>
    <item name="android:shadowDx">1</item>
    <item name="android:shadowDy">2</item>
    <item name="android:shadowRadius">3</item>
</style>

关键是要记住,阴影* 元素不是文本属性。正因为如此将不通过textAppearance应用。

The key thing is to remember that shadow* elements are not text properties. And as such will not be applied via textAppearance.

我要问的Andr​​oid开发者邮件列表上,如果这是期望的行为。

I'm going to ask on the Android Developers Mailing list if this is desired behavior.

这篇关于使用&QUOT;安卓textAppearance&QUOT;在TextView中/ EditText上会失败,但和QUOT;样式&QUOT;作品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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