gpt4 book ai didi

android - 如何在styles.xml中设置TextInputEditText的样式

转载 作者:太空宇宙 更新时间:2023-11-03 12:27:17 26 4
gpt4 key购买 nike

我在注册屏幕中使用 TextInputEditText。我能够设置 float 标签的样式。我想使用样式在 TextInputEditText 的提示和文本上设置自定义字体。有谁知道这是怎么回事?

   <android.support.design.widget.TextInputLayout
android:id="@+id/til_registration_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:paddingEnd="@dimen/default_view_padding_right_8dp"
android:paddingStart="@dimen/default_view_padding_left_8dp"
android:textColorHint="@color/colorSecondaryText"
app:hintTextAppearance="@style/AppTheme.InputLayoutStyle"
app:layout_constraintTop_toBottomOf="@id/textview_registration_title">

<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/registration_name"
android:imeOptions="actionNext"
android:singleLine="true"
android:textColor="@color/colorPrimaryText" />
</android.support.design.widget.TextInputLayout>

样式.xml

<style name="AppTheme.InputLayoutStyle" parent="TextAppearance.AppCompat">
<item name="android:textColor">@color/colorPrimary</item>
<item name="fontFamily">@font/lato_light</item>
</style>

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="android:textViewStyle">@style/AppTheme.TextView</item>
<item name="buttonStyle">@style/AppTheme.Button</item>
</style>

我想为整个应用程序设置样式。

最佳答案

老问题但值得回答。

只需在您的应用主题中设置“textInputStyle”来设置 TextInputLayouts 的样式,设置“editTextStyle”来设置 TextInputEditTexts 的样式。

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="android:textViewStyle">@style/AppTheme.TextView</item>
<item name="buttonStyle">@style/AppTheme.Button</item>
<item name="textInputStyle">
@style/MyCustomTextInputStyle
</item>
<item name="editTextStyle">
@style/MyCustomEditTextStyle
</item>
</style>

<style name="MyCustomTextInputStyle" parent="Widget.Design.TextInputLayout">
<item name="android:textColorHint">@color/colorSecondaryText</item>
<item name="hintTextAppearance">@style/any_style_you_may_want"</item>
</style>

<style name="MyCustomEditTextStyle" parent="Widget.AppCompat.EditText">
<item name="android:textColor">@color/colorPrimary</item>
<item name="fontFamily">@font/lato_light</item>
</style>

这会将相同的样式应用于应用程序中的所有 TextInputLayout 和 TextInputEditText。

关于android - 如何在styles.xml中设置TextInputEditText的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46623448/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com