Nit*_*rma 108 android android-design-library android-textinputlayout
我正在使用android设计库TextinputLayout
.但无法自定义提示颜色,标签颜色和EditText
内部的下划线颜色TextinputLayout
.请帮忙.
Pan*_*ora 242
<item name="colorControlNormal">#c5c5c5</item>
<item name="colorControlActivated">@color/accent</item>
<item name="colorControlHighlight">@color/accent</item>
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请检查此线程.
<style name="TextAppearance.App.TextInputLayout" parent="@android:style/TextAppearance">
<item name="android:textColor">@color/main_color</item>
Run Code Online (Sandbox Code Playgroud)
并使用它像:
<android.support.design.widget.TextInputLayout
...
app:hintTextAppearance="@style/TextAppearance.App.TextInputLayout" >
Run Code Online (Sandbox Code Playgroud)
更新:
并使用如下所示,如果您想要更改提示颜色,当它不是浮动标签时:
<android.support.design.widget.TextInputLayout
...
app:hintTextAppearance="@style/TextAppearance.App.TextInputLayout"
android:textColorHint="#c1c2c4">
Run Code Online (Sandbox Code Playgroud)
感谢@AlbAtNf
Gab*_*tti 34
通过材料组件库,您可以使用com.google.android.material.textfield.TextInputLayout
.
您可以应用自定义样式来更改颜色。
要更改提示颜色,您必须使用以下属性:
hintTextColor
和android:textColorHint
.
<style name="Custom_textinputlayout_filledbox" parent="@style/Widget.MaterialComponents.TextInputLayout.FilledBox">
<!-- The color of the label when it is collapsed and the text field is active -->
<item name="hintTextColor">?attr/colorPrimary</item>
<!-- The color of the label in all other text field states (such as resting and disabled) -->
<item name="android:textColorHint">@color/selector_hint_text_color</item>
</style>
Run Code Online (Sandbox Code Playgroud)
您应该为android:textColorHint
. 就像是:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="0.38" android:color="?attr/colorOnSurface" android:state_enabled="false"/>
<item android:alpha="0.6" android:color="?attr/colorOnSurface"/>
</selector>
Run Code Online (Sandbox Code Playgroud)
要更改底线颜色,您必须使用属性:boxStrokeColor
。
<style name="Custom_textinputlayout_filledbox" parent="@style/Widget.MaterialComponents.TextInputLayout.FilledBox">
....
<item name="boxStrokeColor">@color/selector_stroke_color</item>
</style>
Run Code Online (Sandbox Code Playgroud)
同样在这种情况下,您应该使用选择器。就像是:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?attr/colorPrimary" android:state_focused="true"/>
<item android:alpha="0.87" android:color="?attr/colorOnSurface" android:state_hovered="true"/>
<item android:alpha="0.12" android:color="?attr/colorOnSurface" android:state_enabled="false"/>
<item android:alpha="0.38" android:color="?attr/colorOnSurface"/>
</selector>
Run Code Online (Sandbox Code Playgroud)
您还可以在布局中应用这些属性:
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
app:boxStrokeColor="@color/selector_stroke_color"
app:hintTextColor="?attr/colorPrimary"
android:textColorHint="@color/selector_hint_text_color"
...>
Run Code Online (Sandbox Code Playgroud)
Dou*_*ior 28
基于Fedor Kazakov和其他人的回答,我创建了一个默认配置.
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="Widget.Design.TextInputLayout" parent="AppTheme">
<item name="hintTextAppearance">@style/AppTheme.TextFloatLabelAppearance</item>
<item name="errorTextAppearance">@style/AppTheme.TextErrorAppearance</item>
<item name="counterTextAppearance">@style/TextAppearance.Design.Counter</item>
<item name="counterOverflowTextAppearance">@style/TextAppearance.Design.Counter.Overflow</item>
</style>
<style name="AppTheme.TextFloatLabelAppearance" parent="TextAppearance.Design.Hint">
<!-- Floating label appearance here -->
<item name="android:textColor">@color/colorAccent</item>
<item name="android:textSize">20sp</item>
</style>
<style name="AppTheme.TextErrorAppearance" parent="TextAppearance.Design.Error">
<!-- Error message appearance here -->
<item name="android:textColor">#ff0000</item>
<item name="android:textSize">20sp</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
activity_layout.xml
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Text hint here"
android:text="5,2" />
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
聚焦:
没有焦点:
错误信息:
小智 15
此博客文章描述了各种样式方面EditText
和AutoCompleteTextView
包装TextInputLayout
.
对于EditText
和AppCompat lib 22.1.0+,您可以使用一些与主题相关的设置来设置主题属性:
<style name="StyledTilEditTextTheme">
<item name="android:imeOptions">actionNext</item>
<item name="android:singleLine">true</item>
<item name="colorControlNormal">@color/greyLight</item>
<item name="colorControlActivated">@color/blue</item>
<item name="android:textColorPrimary">@color/blue</item>
<item name="android:textSize">@dimen/styledtil_edit_text_size</item>
</style>
<style name="StyledTilEditText">
<item name="android:theme">@style/StyledTilEditTextTheme</item>
<item name="android:paddingTop">4dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
并应用于EditText
:
<EditText
android:id="@+id/etEditText"
style="@style/StyledTilEditText"
Run Code Online (Sandbox Code Playgroud)
因为AutoCompleteTextView
事情更复杂,因为将其包装TextInputLayout
并应用此主题会破坏浮动标签行为.您需要在代码中修复此问题:
private void setStyleForTextForAutoComplete(int color) {
Drawable wrappedDrawable = DrawableCompat.wrap(autoCompleteTextView.getBackground());
DrawableCompat.setTint(wrappedDrawable, color);
autoCompleteTextView.setBackgroundDrawable(wrappedDrawable);
}
Run Code Online (Sandbox Code Playgroud)
并在Activity.onCreate
:
setStyleForTextForAutoComplete(getResources().getColor(R.color.greyLight));
autoCompleteTextView.setOnFocusChangeListener((v, hasFocus) -> {
if(hasFocus) {
setStyleForTextForAutoComplete(getResources().getColor(R.color.blue));
} else {
if(autoCompleteTextView.getText().length() == 0) {
setStyleForTextForAutoComplete(getResources().getColor(R.color.greyLight));
}
}
});
Run Code Online (Sandbox Code Playgroud)
pm *_*bey 15
在Edittext标签中添加此属性并享受:
android:backgroundTint="@color/colorWhite"
Run Code Online (Sandbox Code Playgroud)
Spi*_*pau 10
ATextinputLayout
不是一个视图,而是一个Layout
,正如Dimitrios Tsigouris在他的博客文章中很好地描述的那样。因此,你不需要Style
,这是Views
唯一的,但使用Theme
。在博客文章之后,我最终得到了以下解决方案:
开始在styles.xml
与
<style name="TextInputLayoutAppearance" parent="Widget.Design.TextInputLayout">
<!-- reference our hint & error styles -->
<item name="android:textColor">@color/your_colour_here</item>
<item name="android:textColorHint">@color/your_colour_here</item>
<item name="colorControlNormal">@color/your_colour_here</item>
<item name="colorControlActivated">@color/your_colour_here</item>
<item name="colorControlHighlight">@color/your_colour_here</item>
</style>
Run Code Online (Sandbox Code Playgroud)
并在您的布局中添加
<com.google.android.material.textfield.TextInputLayout
android:theme="@style/TextInputLayoutAppearance"
...
Run Code Online (Sandbox Code Playgroud)
小智 7
<style name="Widget.Design.TextInputLayout" parent="android:Widget">
<item name="hintTextAppearance">@style/TextAppearance.Design.Hint</item>
<item name="errorTextAppearance">@style/TextAppearance.Design.Error</item>
</style>
Run Code Online (Sandbox Code Playgroud)
您可以覆盖此样式以进行布局
您也可以更改内部 EditText-item 样式。
<style name="EditScreenTextInputLayoutStyle" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorControlNormal">@color/actionBar_background</item>
<item name="colorControlActivated">@color/actionBar_background</item>
<item name="colorControlHighlight">@color/actionBar_background</item>
<item name="colorAccent">@color/actionBar_background</item>
<item name="android:textColorHint">@color/actionBar_background</item>
</style>
Run Code Online (Sandbox Code Playgroud)
将此样式应用于 TextInputLayout
如果你想改变酒吧/线条颜色提示文本颜色的TextInputLayout
(什么口音的颜色通常是),然后就创建这个风格:
<style name="MyStyle">
<item name="colorAccent">@color/your_color</item>
</style>
Run Code Online (Sandbox Code Playgroud)
然后将其TextInputLayout
作为主题应用:
<android.support.design.widget.TextInputLayout
...
app:theme="@style/MyStyle" />
Run Code Online (Sandbox Code Playgroud)
这基本上将一个主题(不是样式)设置为一个视图(而不是整个活动)。
归档时间: |
|
查看次数: |
122860 次 |
最近记录: |