我正在使用TextInputLayout和TetInputEditText来获取浮动提示.现在我想更改编辑文本的提示和底线的颜色.我想让用户点击编辑文本时进行更改.
所以我尝试更改编辑文本的onClickListener颜色.但我没有发现颜色有任何变化.
xml布局:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="vertical">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_item_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="20dp"
android:paddingTop="05dp">
<android.support.design.widget.TextInputEditText
android:layout_width="240dp"
android:layout_height="45dp"
android:id="@+id/editTextItemName"
android:layout_gravity="center_horizontal"
android:hint="@string/item_name"
android:textSize="12sp" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
java代码:
public void setUpUI(){
edt_Item_Name = (TextInputEditText) findViewById(R.id.editTextItemName);
edt_Item_quantity = (TextInputEditText)findViewById(R.id.editTextItemQuantity);
edt_Item_Unit = (TextInputEditText)findViewById(R.id.editTextItemUnit);
textInput_Item_name = (TextInputLayout)findViewById(R.id.input_layout_item_name);
textInput_Item_quantity = (TextInputLayout)findViewById(R.id.input_layout_item_quantity);
textInput_Item_Unit = (TextInputLayout)findViewById(R.id.input_layout_item_unit);
edt_Item_Name.getBackground().mutate().setColorFilter(ContextCompat.getColor(this, R.color.edtColor), PorterDuff.Mode.SRC_ATOP);
edt_Item_Name.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
edt_Item_Name.setHintTextColor(ContextCompat.getColor(SearchActivity.this, R.color.edtColor));
edt_Item_Name.getBackground().mutate().setColorFilter(ContextCompat.getColor(SearchActivity.this, R.color.edtColor), PorterDuff.Mode.SRC_ATOP);
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
java android colors android-textinputlayout android-textinputedittext
我在“NullPointerException: Attempt to invoke virtual method 'void android.view.View.getBoundsOnScreen(android.graphics.Rect)' on a null object reference”崩溃日志中发现崩溃,我验证了一些关于这次崩溃的stackoverflow建议。我发现下面的链接建议在 TextInputLayout 中使用提示而不是 TextInputEditText,所以我想知道是什么让它与众不同?
下面的链接显示在TextInputLayout使用提示: SO 谷歌显示在TextInputEditText使用提示: Google_Recommendation
我在 TextInputLayout 和 TextInputEditText 的两个地方都尝试了提示。提示同样在两个地方都运行良好。
我想知道这两种方法有什么区别,哪一种更适合使用。
如果我使用最新的材质库版本com.google.android.material:material:1.2.0-alpha02,我在 TextInputEditText 和他的提示消息方面遇到了一些麻烦。我设置了 5 行可滚动 textInputEditText 并且我想显示提示消息与该文本输入的上边距对齐。在布局编辑器上出现在正确的位置,但是当我运行应用程序时,位置是垂直居中的。为什么 ?
相反,我没有遇到这个问题com.google.android.material:material:1.1.0-beta02
这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="@+id/sendMailContainer"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/popupTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="@string/sendBusinessCard"
android:textColor="@android:color/black"
android:textSize="22sp" />
<TextView
android:id="@+id/subTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sendBusinessCard"
android:textColor="@android:color/black"
android:textSize="18sp"
android:layout_below="@+id/popupTitle"
android:layout_marginEnd="40dp"
android:layout_marginStart="40dp"
android:layout_marginTop="20dp"/>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/noteMessageContainer"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/subTitle"
android:layout_marginEnd="40dp"
android:layout_marginStart="40dp"
android:layout_marginTop="10dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/noteMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/emailText"
android:inputType="text|textMultiLine|textCapSentences"
android:textColor="@android:color/black"
android:textColorHint="@color/gray9B"
android:textSize="16sp"
android:isScrollContainer="true"
android:scrollbars="vertical"
android:textIsSelectable="true"
android:minLines="5"
android:maxLines="5"
android:gravity="top"/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/notePopupLeftButton"
android:layout_width="180dp"
android:layout_height="35dp"
android:layout_alignParentStart="true"
android:layout_below="@+id/noteMessageContainer"
android:layout_marginBottom="20dp"
android:layout_marginStart="20dp" …Run Code Online (Sandbox Code Playgroud) android android-layout android-textinputlayout android-textinputedittext material-components-android
我为我的密码字段选择了 TextInputEditText,以使用切换密码功能。
这是我的 xml 代码:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="@dimen/login_width"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/password_margin_top"
app:hintEnabled="false"
app:passwordToggleDrawable="@drawable/password_toggle_drawable"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/my_login_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:hint="@string/password"
android:inputType="textPassword"
android:nextFocusDown="@+id/my_login_login"
android:padding="@dimen/field_padding" />
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
我必须对切换密码进行一些其他布局更改。在 TextInputLayout 中是否有任何可用的回调?
我有一个文本输入布局,里面有文本输入编辑文本。文本输入编辑文本在末尾有一个 Drawable。我想要实现的是在单击时使可绘制对象在最后执行某些操作,例如显示 Toast 消息
下面是我的 XML 代码
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_toast"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:padding="3dp">
<!--android:maxLength="13"-->
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_toast"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableEnd="@drawable/ic_calendar"
android:drawableRight="@drawable/ic_calendar"
android:hint="@string/date_from"
android:inputType="date" />
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点
android android-edittext android-textinputlayout android-textinputedittext
我必须使用浮动提示标签制作一个textinputlayout,它需要具有白色背景。一些与此类似的东西
设计预期:
但是到目前为止,我所能做的就是:
使用TextInputLayout的实际设计:

当前,TextInputLayout中的提示标签具有透明背景。有人可以帮助我,告诉如何实现这一目标吗?
这是我的代码(texinput布局):
<android.support.design.widget.TextInputLayout
android:id="@+id/til_login_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/text_input_layout_background"
app:hintTextAppearance="@style/TextStyle.Small.Hint">
<EditText
android:id="@+id/login_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:gravity="center_vertical"
android:hint="Email / Mobile"
android:inputType="text"
android:textSize="14sp" />
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
我正在使用的背景
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:gravity="bottom"
android:top="5dp">
<shape android:shape="rectangle">
<stroke
android:width="1px"
android:color="@color/Grey300" />
<corners android:radius="100dp" />
<solid android:color="@color/transparent" />
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我希望你能帮助我解决我现在面临的问题.
我使用TextInputEditText创建了一个自定义搜索视图,它实际上非常简单,并且除了5.1(Lollipop)之外的所有Android版本都能正常工作,EditText在写入时甚至不会隐藏提示甚至显示光标,文本也不是可见.
我已经尝试过我所知道的一切,但我无法想象它会是什么.
非常感谢您的参与.
这是我的自定义类视图:
public class CustomSearchView extends RelativeLayout {
@BindView(R.id.csvIcon) ImageView csvIcon;
public @BindView(R.id.csvEditText) TextInputEditText editText;
public CustomSearchView(Context context) {
super(context);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.custom_search_view, this, true);
ButterKnife.bind(this);
}
public CustomSearchView(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.custom_search_view, this, true);
ButterKnife.bind(this);
TypedArray typedArray = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.CustomSearchView,
0, 0);
String hintText = typedArray.getString(R.styleable.CustomSearchView_hintText);
try {
int max = typedArray.getInteger(R.styleable.CustomSearchView_csv_length, 17);
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(max)});
editText.setInputType(typedArray.getInt(R.styleable.CustomSearchView_android_inputType, InputType.TYPE_CLASS_TEXT));
editText.setHint(hintText);
csvIcon.setImageDrawable(typedArray.getDrawable(R.styleable.CustomSearchView_csv_icon));
} catch (Exception e) …Run Code Online (Sandbox Code Playgroud) java android android-edittext android-5.0-lollipop android-textinputedittext
有谁知道在使用TextInputEditText和时如何显示总计行数TextInputLayout?使用不带的普通EditText时,我没有这个问题TextInputLayout。这是我的示例代码:
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_small"
app:counterEnabled="true"
app:counterMaxLength="1000"
app:counterOverflowTextAppearance="@style/TextLimitError"
app:hintTextAppearance="@style/TextAppearance.App.TextInputLayout"
app:theme="@style/TextInputLayoutStyle">
<android.support.design.widget.TextInputEditText
android:id="@+id/input"
style="@style/TextInputEditTextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="hint text"
android:inputType="textMultiLine"
android:lines="5"
android:maxLength="1000"/>
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
我的目标是textarea在设置rows属性时具有与html相同的效果。
这是我在上设置时得到android:lines的TextInputEditText。它在浮动标签和我输入的第一个字母之间留有空白。
android text multiline android-layout android-textinputedittext
我正在使用密码切换来显示和隐藏密码。而且我不想使用自定义 drawable。但是,当此编辑文本生成错误时,它会覆盖切换密码图标,并且无法向该图标添加填充或边距。如果对此有任何解决方案,那将是一种乐趣。这是我正在使用的代码:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textColorHint="@color/white"
app:passwordToggleEnabled="true"
app:passwordToggleTint="@color/white">
<EditText
android:id="@+id/et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/white"
android:hint="@string/password"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:maxLength="40"
android:maxLines="1"
android:textColor="@color/white"
android:textColorHint="@color/app_green_color" />
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud) android android-textinputlayout android-textinputedittext material-components material-components-android
如何单击每个 TextInputEditText 的 drawableRight 编辑图像?我想单击编辑图标,然后启用编辑每个字段。我怎样才能做到这一点?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--First name-->
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="@dimen/_64dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/etFirstName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:drawableRight="@drawable/icon_edit"
android:hint="@string/label_fname"
android:inputType="textCapWords" />
</com.google.android.material.textfield.TextInputLayout>
<!--Middle name-->
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/activity_registration_tiMiddleName"
android:layout_width="match_parent"
android:layout_height="@dimen/_64dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/etMiddleName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:drawableRight="@drawable/icon_edit"
android:hint="@string/label_mname"
android:inputType="textCapWords"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
那么如何使用 drawbleRight 单独编辑每个字段。请帮忙。
android onclicklistener android-textinputlayout android-textinputedittext material-components-android
我的布局中有一堆 TextInputEditText,定义如下:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/confirmPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/registration_confirm_password"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
当用户尝试提交表单时,我有一个验证方法来检查每个字段并在无效字段上设置错误,如下所示:
if(confirmPassword.text.toString() != password.text.toString()) {
confirmPassword.error = "Passwords don't match"
confirmPassword.setOnKeyListener { _, _, _ ->
confirmPassword.error = null
true
}
valid = false
}
Run Code Online (Sandbox Code Playgroud)
一旦用户开始纠正他的错误,OnKeyListener 就会立即消除错误。
这段代码在我的模拟器和我的 Android 5.1.1 设备上完美运行。但是在我的一个用户的设备上,三星 Galaxy S6 Edge 和 Android 6.0,当他犯了一个错误并且一个字段上有错误时,他不能再编辑它了。
我使用 TextInputEditText 错了吗?这是一个已知的错误吗?有解决方法吗?
问题 1: TextInputLayout 正在更改 endIconDrawable 的颜色,默认情况下它是绿色和白色,但它正在更改为灰色,那么我该如何阻止它?
问题 2:我只想在用户单击 TextInputLayout 并开始输入时更改 backgroundtint 或下划线颜色,因此如何操作。
代码:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/d"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_10sdp"
app:endIconMode="custom"
app:endIconDrawable="@drawable/green"
app:endIconContentDescription="@string/D"
android:hint="@string/D">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud) android material-design android-textinputlayout android-textinputedittext