Che*_*eng 5 java android android-layout android-textinputlayout
我有一个TextInputLayout。我尝试应用自定义hintTextAppearance样式
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/wizard_horizontal_margin"
android:paddingRight="@dimen/wizard_horizontal_margin"
android:paddingTop="@dimen/wizard_vertical_margin"
android:paddingBottom="@dimen/wizard_vertical_margin">
<TextView
android:paddingBottom="@dimen/wizard_vertical_margin"
android:text="What's your email address?"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?attr/wizardTextViewColor"
android:textSize="18sp"
android:id="@+id/text_view" />
<android.support.design.widget.TextInputLayout
app:hintTextAppearance="@style/WizardTextInputLayout"
android:id="@+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="Email address"
android:id="@+id/email_edit_text" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我尝试通过应用以下自定义样式使文本变为粗体。
<style name="WizardTextInputLayout" parent="TextAppearance.Design.Hint">
<item name="android:textStyle">bold</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但是,在应用自定义样式之前和之后看起来都没有什么不同。
hintTextAppearance样式之前hintTextAppearance样式后我可以确认样式工作。因为,如果我android:textSize在WizardTextInputLayout样式中添加属性,则可以看到浮动标签文本大小发生了变化。
但是,为什么使浮动标签文本变为粗体不起作用?我有什么可以尝试使浮动标签文本加粗的?
由于为textinputLayout设置自定义字体会影响其管理的提示文本外观和样式,因此您可以使用提供自定义文本样式xml的setHintTextAppearance(int resId)方法来解决该问题。TextInputLayout
您可以创建一个自定义类来扩展该类TextInputLayout并覆盖该setTypeFace()方法:
@Override
public void setTypeface(@Nullable Typeface typeface) {
setTypeface(Your_Bold_typeface);
}
Run Code Online (Sandbox Code Playgroud)
您应该在其中设置从所需字体的粗体版本创建的字体。
| 归档时间: |
|
| 查看次数: |
1395 次 |
| 最近记录: |