Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法获取TextInputLayout&;text输入text在禁用时正确设置样式_Android_Material Design - Fatal编程技术网

Android 无法获取TextInputLayout&;text输入text在禁用时正确设置样式

Android 无法获取TextInputLayout&;text输入text在禁用时正确设置样式,android,material-design,Android,Material Design,我在Android项目中使用了多个新的TextInputLayout和TextInputItemText对象,如下所述: 但是,无论我做什么,当字段被禁用时,我都无法使其显示为“灰色”。事实上,两种情况看起来都一样 以下是我在布局中如何定义它: <android.support.design.widget.TextInputLayout android:id="@+id/username_wrapper" style="@st

我在Android项目中使用了多个新的TextInputLayout和TextInputItemText对象,如下所述:

但是,无论我做什么,当字段被禁用时,我都无法使其显示为“灰色”。事实上,两种情况看起来都一样

以下是我在布局中如何定义它:

        <android.support.design.widget.TextInputLayout
            android:id="@+id/username_wrapper"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/header_container"
            android:layout_marginLeft="@dimen/list_verticle_margin"
            android:hint="@string/username">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/username_field"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textEmailAddress" />
        </android.support.design.widget.TextInputLayout>


我忘了我问了这个问题

下面是我如何解决它的(但它会影响所有文本输入)

  • 覆盖colors.xml文件中禁用的颜色:
  • 919191

  • 从代码中将TextInputLayout和TextInputItemText设置为禁用。希望这对别人有帮助 更新:您不再需要覆盖“mtrl\u textinput\u disabled\u color”。 使用新材质组件,您可以设置如下样式:

    <style name="example.TextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
        <item name="boxStrokeColor">@color/example_color</item>
        //// Other stuff here if you want.
    </style>
    

    在它的xml中。这提供了更大的灵活性,并允许您根据需要单独设置每个TextInputLayout的样式。

    好的,现在看来:与其禁用edittext,还需要禁用布局部分。另外,您需要在colors.xml中覆盖mtrl_textinput_disabled_color。所以我想我现在就要这么做了。()有同样的问题,看起来好像坏了。很好。但是,您知道从XML设置禁用状态有什么问题吗?它似乎根本不起作用。对不起,一点线索也没有。我自己也还是有点不对劲。
    <style name="example.TextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
        <item name="boxStrokeColor">@color/example_color</item>
        //// Other stuff here if you want.
    </style>
    
    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/colorAccent" android:state_focused="true"/>
    <item android:color="@color/disabled" android:state_enabled="false"/>
    <item android:color="@color/textDefault"/>
    </selector>
    
    style="@style/example.TextInputLayout"