繁体   English   中英

TextInputEditText在Android 5.1上不起作用

[英]TextInputEditText don't work on Android 5.1

我希望您能帮助我解决当前遇到的问题。

我使用TextInputEditText创建了一个自定义搜索视图,实际上非常简单,并且在所有Android版本上都可以正常工作,除了5.1(Lollipop)之外,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) {
        e.printStackTrace();
    }
}

public CustomSearchView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}
}

这是属性规范:

<declare-styleable name="CustomSearchView">
    <attr name="csv_icon" format="reference"/>
    <attr name="hintText" format="string"/>
    <attr name="csv_length" format="integer"/>
    <attr name="android:inputType"/>
    <attr name="android:digits"/>
</declare-styleable>

这是我的XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/charcoal_grey_two">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/csvIcon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="10dp"
            android:src="@drawable/icon_search"/>

        <android.support.design.widget.TextInputEditText
            android:id="@+id/csvEditText"
            android:layout_width="match_parent"
            android:layout_height="45dp"
            android:layout_gravity="center"
            android:cursorVisible="true"
            android:focusableInTouchMode="true"
            android:layout_marginLeft="10dp"
            android:imeOptions="actionSearch"
            android:inputType="textAutoComplete"
            android:textSize="20dp"
            android:textColorHint="@color/slate_grey"
            android:textColor="@color/slate_grey"
            android:background="@android:color/transparent"/>

    </LinearLayout>

</RelativeLayout>

这是我在片段中的实现:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:background="@color/gunmetal">

<mx.com.segurosbancomer.gpsajustadores.view.custom.TopBarLayout
    android:id="@+id/topBar"
    android:layout_width="match_parent"
    android:layout_height="45dp"
    app:tb_color="@color/gunmetal"
    app:tb_text="@string/bf_title"
    app:tb_text_color="@color/white"
    app:tb_btnleft_visibility="0"
    app:tb_btnright_visibility="8"
    app:tb_btnleft="@drawable/icon_prev_white"
    app:tb_btnright="@drawable/icon_dot_gray"/>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="10dp"
    android:orientation="vertical">

    <mx.com.segurosbancomer.gpsajustadores.view.custom.CustomTextView
        android:id="@+id/tituloPoliza"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/bf_search"
        android:textColor="@color/white"
        android:textSize="18dp"
        android:layout_margin="10dp"
        app:ctv_customFont="stagsansbook.otf" />


    <mx.com.segurosbancomer.gpsajustadores.view.custom.CustomSearchView
        android:id="@+id/searchPoliza"
        android:layout_width="match_parent"
        android:layout_height="45dp"
        android:layout_margin="10dp"
        android:cursorVisible="true"
        android:focusableInTouchMode="true"
        android:inputType="textAutoComplete"
        android:digits="ABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890"
        app:csv_length="30"
        app:csv_icon="@drawable/icon_search"
        app:hintText="@string/bf_poliza" />

    <mx.com.segurosbancomer.gpsajustadores.view.custom.CustomSearchView
        android:id="@+id/searchInciso"
        android:layout_width="match_parent"
        android:layout_height="45dp"
        android:layout_margin="10dp"
        android:cursorVisible="true"
        android:focusableInTouchMode="true"
        android:inputType="textAutoComplete"
        android:digits="ABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890"
        app:csv_length="30"
        app:csv_icon="@drawable/icon_search"
        app:hintText="@string/bf_inciso" />


    <View
        android:layout_width="match_parent"
        android:layout_height="3dp"
        android:background="@color/charcoal_grey_two"/>

    <mx.com.segurosbancomer.gpsajustadores.view.custom.CustomTextView
        android:id="@+id/tituloSerie"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/bf_search_serie"
        android:textColor="@color/white"
        android:textSize="18dp"
        android:layout_margin="10dp"
        app:ctv_customFont="stagsansbook.otf" />

    <mx.com.segurosbancomer.gpsajustadores.view.custom.CustomSearchView
        android:id="@+id/searchSerie"
        android:layout_width="match_parent"
        android:layout_height="45dp"
        android:layout_margin="10dp"
        android:cursorVisible="true"
        android:focusableInTouchMode="true"
        android:inputType="textAutoComplete"
        android:digits="ABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890"
        app:csv_length="17"
        app:csv_icon="@drawable/icon_search"
        app:hintText="@string/bf_serie"/>


</LinearLayout>

</LinearLayout>

最后,我找到了解决方案。 如果其他人也有类似的问题,可以通过从AndroidManifest.xml中删除这一行来解决。

android:hardwareAccelerated="false"

该行允许片段和所有组件完美地工作。

您应该将TextInputEditTextTextInputLayout一起使用。 只需使用EditText 看到这个: https : //stackoverflow.com/a/37834022/5558150

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM