[英]how to change TextInputLayout error color and Text size of Error dynamically with code
[英]How to set the TextInputLayout error Color and size dynamically With Code
我想在動態 TextInputLayout 中使用 app:errorTextAppearance="@style/TextLabelInput" 比如何使用它。
<style name="TextLabelInput" parent="TextAppearance.AppCompat">
<!-- Hint color and label color in FALSE state -->
<item name="android:textColorHint">@color/solid_red</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">@color/solid_red</item>
<item name="android:duration">200</item>
<item name="android:textColorHighlight">@color/solid_red</item>
<!-- Label color in TRUE state and bar color FALSE and TRUE State -->
<item name="colorAccent">@color/solid_red</item>
<item name="colorControlNormal">@color/solid_red</item>
<item name="colorControlActivated">@color/solid_red</item>
<item name="colorPrimary">@color/solid_red</item>
<item name="colorPrimaryDark">@color/solid_red</item>
</style>
TextInputLayout input
input = new TextInputLayout(this);
input.setLayoutParams(lparams);
input.setTypeface(tf);
我為此找到了靈魂。 我在我的代碼中這樣做
<!-- Firstly Make a Xml of TextInputLayout and Edittext Layout -->
<!-- Text Input Layout-->
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.TextInputLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
app:errorTextAppearance="@style/TextLabelInput"
/>
<!-- Edittext Layout -->
<?xml version="1.0" encoding="utf-8"?>
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/txt_color"
android:textColorHint="@color/txt_color"
android:textColorHighlight="@color/txt_color"
android:textSize="21sp" />
<!-- In code add this with dynamic Text -->
TextInputLayout input
input = new TextInputLayout(this);
input =(TextInputLayout)getLayoutInflater().inflate(R.layout.row_inputlayout_item, null);
input.setLayoutParams(lparams);
input.setTypeface(tf);
et= new EditText(this);
et= (EditText)getLayoutInflater().inflate(R.layout.row_edittext_form, null);
et.setId(Integer.parseInt(item.getFieldid()));
et.setLayoutParams(lparams);
et.setHint(item.getLabel());
input.addView(et);
rl_MainLayout1.addView(input);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.