tiper / MaterialSpinner

Implementation of a Material Spinner for Android with TextInputLayout functionalities
Apache License 2.0
130 stars 30 forks source link

Focus bug #6

Closed petr-stety-stetka closed 4 years ago

petr-stety-stetka commented 4 years ago

Hi,

I managed to find an unpleasant bug. When I open spinner dropdown I cant' close it. It propably try focus something and reopening spinner dropdown constantly.

However bug is only when MaterialSpinner is first focusable view in layout. Like this:

<LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        >
      <com.tiper.MaterialSpinner
            android:hint="@string/hint_category"
            android:id="@+id/categoryTypeSpinner"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:visibility="gone"
            app:boxBackgroundColor="@android:color/transparent"
            style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
            />
</LinearLayout>

When I add some focusable view like this:

<LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        >
    <!-- Dirty hack. -->
    <com.google.android.material.textfield.TextInputLayout
            android:layout_height="1dp"
            android:layout_width="1dp"
            app:boxBackgroundColor="@android:color/transparent"
            style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
            >
        <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/titleTextEdit"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                />
    </com.google.android.material.textfield.TextInputLayout>
    <com.tiper.MaterialSpinner
            android:hint="@string/hint_category"
            android:id="@+id/categoryTypeSpinner"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:visibility="gone"
            app:boxBackgroundColor="@android:color/transparent"
            style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
            />
</LinearLayout>

Material spinner will work fine.

tiper commented 4 years ago

Please check https://github.com/tiper/MaterialSpinner/issues/4#issuecomment-505515790

petr-stety-stetka commented 4 years ago

Thanks, this lines added to spinner parent view and now it works fine.

android:descendantFocusability="beforeDescendants"`
android:focusable="true"
android:focusableInTouchMode="true"
githeyj commented 4 years ago
android:descendantFocusability="beforeDescendants"`
android:focusable="true"
android:focusableInTouchMode="true"

I added the above lines of code but still couldn't sort the issue. Anybody who has succeded yet?

rajvimal commented 4 years ago

How do i implement style in java code programatically.I tried in two ways such as :

1st : com.tiper.MaterialSpinner materialSpinner = new com.tiper.MaterialSpinner(this,null,R.style.Widget_MaterialComponents_TextInputLayout_OutlinedBox); ///// Not working

2nd : com.tiper.MaterialSpinner spinner = new com.tiper.MaterialSpinner(new androidx.appcompat.view.ContextThemeWrapper(this, R.style.Widget_MaterialComponents_TextInputLayout_OutlinedBox));

tiper commented 4 years ago

Hi @rajvimal your question seems unrelated with this issue.

I've moved your question to #27