加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

如何为TextInputLayout创建浮动标签粗体

发布时间:2020-12-15 02:17:11 所属栏目:Java 来源:网络整理
导读:我有一个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:orient
我有一个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>

我尝试通过应用以下自定义样式使文本变为粗体.

<style name="WizardTextInputLayout" parent="TextAppearance.Design.Hint">
    <item name="android:textStyle">bold</item>
</style>

但是,它之前看起来并没有什么不同.应用自定义样式后.

在自定义hintTextAppearance样式之前

enter image description here

自定义hintTextAppearance样式后

enter image description here

我可以确认造型工作.因为,如果我在WizardTextInputLayout样式中添加android:textSize属性,我可以看到浮动标签文本大小有变化.

但是,为什么将浮动标签文本设为粗体不起作用?我可以尝试将浮动标签文字加粗吗?

解决方法

更新

由于为textinputLayout设置自定义字体会影响由其提供的提示文本外观和样式,因此可以使用TextInputLayout的setHintTextAppearance(int resId)方法,并提供自定义文本样式xml来克服此问题.

原始答案

您可以创建一个扩展TextInputLayout类并重写setTypeFace()方法的自定义类:

@Override
public void setTypeface(@Nullable Typeface typeface) {
    setTypeface(Your_Bold_typeface);
}

您应该在哪里设置从所需字体的粗体版本创建的字体.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读