这是我的xml
<android.support.design.widget.TextInputLayout
style="@style/main_input_text"
android:layout_marginTop="@dimen/activity_medium_margin"
app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout">
<android.support.v7.widget.AppCompatEditText
style="@style/main_edit_text"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
这就是风格
<style name="main_input_text">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">@dimen/activity_edittext_height</item>
<item name="android:background">@drawable/mc_shape_border_button_transparent</item>
<item name="android:gravity">center_vertical</item>
<item name="android:paddingTop">@dimen/activity_extra_small_margin</item>
<item name="android:paddingBottom">@dimen/activity_extra_small_margin</item>
<item name="android:keyTextSize">8sp</item>
<item name="android:textSize">8sp</item>
</style>
我找不到像hintSize,textSize和keyTextSize这样的东西没有帮助
答案 0 :(得分:104)
在styles.xml中
<style name="TextLabel" parent="TextAppearance.Design.Hint">
<item name="android:textSize">16sp</item>
</style>
然后在你的布局文件中:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="12dp"
app:hintTextAppearance="@style/TextLabel"
android:minHeight="30dp">
答案 1 :(得分:5)
以XML格式更改TextInputLayout&#39; app:errorTextAppearance
。
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:errorTextAppearance="@style/CustomTextInputLayoutStyle.ErrorTextStyle">
CustomTextInputLayoutStyle.ErrorTextStyle
中将styles.xml
定义为
<style name="CustomTextInputLayoutStyle.ErrorTextStyle" parent="TextAppearance.Design.Error">
<item name="android:textSize">10sp</item>
</style>
答案 2 :(得分:1)
1)使用样式
将hintTextAppearance
添加到InputLayout
<android.support.design.widget.TextInputLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintTextAppearance="@style/TextInputLayoutHintText" >
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp" />
</android.support.design.widget.TextInputLayout>
2)然后只需将样式添加到styles.xml
<style name="TextInputLayoutHintText">
<item name="android:textColor">@color/gray</item>
<item name="android:textSize">12sp</item></style>
答案 3 :(得分:0)
@SantiagoMartínez答案仅适用于非空Edittext
(在TextInputLayout
内部)的提示
但是对于空的Edittext
,TextInputLayout
提示从Edittext
textSize
获得属性。
答案 4 :(得分:-2)
您可以减少EditText上的字体大小 - 这也会减小提示的大小。即android:textSize =&#34; 16sp&#34;