这是我的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的东西
我正在创建简单的AppCompatEditText,添加OnFocusChangeListener并将其放在简单的TextInputLayout中.
当AppCompatEditText失去焦点时,它的内容应该通过isValidParam方法验证.
它工作到昨天,当我使用rev.23.0.3但是现在,当我使用rev.24.0.2时,它在isValidParam方法的第1行给出如下错误.
java.lang.ClassCastException:android.widget.FrameLayout无法强制转换为android.support.design.widget.TextInputLayout
我检查了调试模式.AppCompatEditText.getpParent()确实返回Framelayout而不是TextInputLayout.
LinearLayout llParams = new LinearLayout(context);
llParams.setOrientation(LinearLayout.VERTICAL);
// Create label for param
final TextInputLayout tilParam = new TextInputLayout(context);
// Add label into layout
llParams.addView(tilParam);
// Create Editor for param
final AppCompatEditText etParam = new AppCompatEditText(context);
edParam.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if (!hasFocus)
            if (isValidParam(etParam)) {
                do some thing;
            } else {
                do other thing;
            }
    }
});
tilParam.addView(etParam);
// validation method
boolean isValidParam(AppCompatEditText editText) {
    TextInputLayout til = (TextInputLayout) editText.getParent(); …android android-appcompat android-design-library android-textinputlayout textinputlayout
我在TextInputLayout中包含了一个EditText.我希望在EditText下显示错误,但是对齐到屏幕的右端.
我的XML是这样的:
        <android.support.design.widget.TextInputLayout
            android:id="@+id/text_input_email"
            style="@style/forgot_pass_text_inputlayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/tv_enter_email_message"
            android:layout_marginTop="@dimen/email_padding_top"
            android:hintTextAppearance="@{forgotPasswordVM.hintTextAppearance}"
            android:theme="@style/forgot_pass_til_state"
            app:error="@{forgotPasswordVM.email.textInputError}">
            <EditText
                android:id="@+id/actv_email"
                style="@style/forgot_pass_edit_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/email_address"
                android:imeActionId="@+id/btn_submit"
                android:imeOptions="actionSend"
                android:inputType="textEmailAddress"
                android:maxLines="1"
                android:onEditorAction="@{forgotPasswordVM.onEditorAction}"
                android:singleLine="true"
                app:binding="@{forgotPasswordVM.email.text}" />
        </android.support.design.widget.TextInputLayout>
我正在使用数据绑定.
我试过设置android:gravity="right"和android:layout_gravity="right"上都的EditText和TextInputLayout.两者都不是我想要的方式.
我尝试在主题和风格中设置正确的重力.对错误都没有任何影响.
我已经在其中应用的样式上尝试了正确的重力app:errorTextAppearance="@style/right_error".即使这样也行不通.
我尝试通过在此链接后使用带有AlignmentSpan的SpannableStringBuilder以编程方式将Error转移到右侧.即使这对我也不起作用.
我不知道还有什么可以尝试的.请建议.
我正在尝试为Xamarin Forms构建渲染器.渲染器需要EditText在选中时将下划线颜色设置为"活动颜色",并在取消选择时将其设置为"提示颜色".我的初始设置看起来像这样.
注意:这里的路径完整的源文件
https://github.com/XamFormsExtended/Xfx.Controls/blob/issue-%236/src/Xfx.Controls.Droid/Renderers/XfxEntryRendererDroid.cs 
// called when control is created or when Colors are changed.
protected virtual void SetLabelAndUnderlineColor()
{
    var defaultColor = GetPlaceholderColor();
    var activeColor = GetActivePlaceholderColor();
    SetHintLabelDefaultColor(defaultColor);
    SetHintLabelActiveColor(activeColor);
    SetUnderlineColor(_hasFocus ? activeColor : defaultColor);
}
private void SetUnderlineColor(AColor color)
{
    var bg = ColorStateList.ValueOf(color);
    ViewCompat.SetBackgroundTintList(EditText,bg);
}
private void SetHintLabelActiveColor(AColor color)
{
    var hintText = Control.Class.GetDeclaredField("mFocusedTextColor");
    hintText.Accessible = true;
    hintText.Set(Control, new ColorStateList(new int[][] { new[] { 0 } }, new int[] { color }));
}
private void SetHintLabelDefaultColor(AColor …我想用Widget.MaterialComponents.TextInputLayout.OutlinedBox样式创建TextInputLayout.我尝试了很多方法,但无法获得所需的结果.这是我的代码.
TextInputLayout textInputLayout = new TextInputLayout(getActivity(),null,R.style.Widget_MaterialComponents_TextInputLayout_OutlinedBox);
textInputLayout.setHint("My Hint");
TextInputEditText editText = new TextInputEditText(textInputLayout.getContext());
textInputLayout.addView(editText);
parentView.addView(textInputLayout);
我也尝试过:
TextInputLayout textInputLayout = new TextInputLayout(getActivity(),null,TextInputLayout.BOX_BACKGROUND_OUTLINE);
android android-layout android-styles material-design textinputlayout
我在网上尝试过很多选项,但似乎都没有.
我已将此XML用于此目的.
<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:hintTextAppearance="@style/TextLabel">
    <com.projects.fonts.RobotoEditText
        style="@style/EditText"
        android:hint="@string/description"
        android:singleLine="false"
        app:font="@string/roboto_regular" />
</android.support.design.widget.TextInputLayout>
我也定了
<item name="android:singleLine">false</item>
在TextLabel和EditText中.但他们都没有工作.
我已经以通常的方式使用密码字段实现了TextInputLayout:
<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <EditText
        android:id="@+id/returning_password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/prompt_password"
        android:inputType="textPassword"
        android:maxLines="1"
        android:textSize="14sp" />
</android.support.design.widget.TextInputLayout>
这在使用Android版本24.0.2的Android支持库时工作正常,但在切换到25.0.1之后:
compile 'com.android.support:design:25.0.1'
compile 'com.android.support:support-v4:25.0.1'
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:support-vector-drawable:25.0.1'
我不再在窗口小部件中看到密码可见性切换(也称为"眼睛图标").更改到最新版本25.1.0不能解决此问题.
是否有任何我错过的,需要与支持库25一起更改,或者这可能是Android问题?
我有这样的 XML 布局:
 <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout
        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:layoutDirection="locale" 
        android:textDirection="rtl"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".app.storey.view.StoreyInsertFragment">
    <com.google.android.material.textfield.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="somthing"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginEnd="8dp"
            android:layout_marginTop="8dp"
            app:layout_constraintStart_toStartOf="parent"
            android:layout_marginStart="8dp"
            app:layout_constraintHorizontal_bias="0.0" 
            app:layout_constraintTop_toTopOf="parent">
        <com.google.android.material.textfield.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>
    </com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
我希望hint文字显示在右侧,但使用后layoutDirection,textAlignment仍然显示在左侧,我该怎么做?
我看到这个链接但没有解决我的问题。
我的提示文本总是可以顶部,好像它是可聚焦的吗?
我试过这个:
 <android.support.design.widget.TextInputLayout
            android:id="@+id/etSurnameInput"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/llNameImage"
            android:hint="My Hint Text"
            app:hintEnabled="true"
            app:hintAnimationEnabled="false"
            android:textColorHint="@color/gray_title">
我在用着TextInputLayout。我设置了它的提示来string.xml应用本地化。因此,从下拉列表中更改语言后,我使用recreate()使用所选语言资源刷新整个活动组件的方法,但TextInputLayout提示没有刷新。