【发布时间】:2015-07-24 07:48:23
【问题描述】:
我有一些在片段中使用的 TextInputLayout。现在,对于其中一些的提示,我需要显示下标或上标(例如 gn 或 s2)。当我在字符串资源中使用这些标签时,它们不会显示。我的资源如下所示:
<string name="some_string">meters<sup>2</sup></string>
关于 TextInputLayout,我尝试在 XML 和编程方式中设置提示,但没有成功,如下所示:
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout_example"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/editText_example"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:digits="0123456789."
android:selectAllOnFocus="true"
android:ems="10"
android:singleLine="true"
android:maxLines="1"
android:scrollHorizontally="true"
android:hint="@string/some_string"/>
</android.support.design.widget.TextInputLayout>
和
TextInputLayout mTextInputLayout = (TextInputLayout) rootView.findViewById(R.id.textInputLayout_example);
mTextInputLayout.setHint(Html.fromHtml(getString(R.string.some_string)));
现在,我知道在开发人员指南中只提到支持<b>, <i>, and <u>,但查看https://github.com/android/platform_frameworks_base/blob/lollipop-mr1-release/core/java/android/content/res/StringBlock.java#L166 你会发现支持更多的标签。
话虽如此,似乎没有任何标签在工作。例如,如果我使用<i> 标记,则文本不是斜体。此外,我尝试在纯 TextView 上使用相同的字符串资源,但它在那里也不起作用。一开始我以为只是M-DP2的问题,于是在KitKat模拟器上试了一下,还是不行。
有人有什么想法吗?
【问题讨论】:
-
我的解决方案有效吗?
标签: android material-design android-design-library