Cheok Yan Cheng
Cheok Yan Cheng

Reputation: 42690

Some style attributes are missing after migrating from support library to AndroidX

By refering to https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/layout/simple_spinner_item.xml and https://pep-security.lu/gitlab/android/pep/blame/2f5b1397ba73f78f49f2094b9fb370d2fee62635/k9mail/src/main/res/layout/simple_spinner_item.xml

Currently, we have the following dropdown view item. It is using style ?android:attr/spinnerDropDownItemStyle

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="8dp"
    android:paddingRight="8dp">

    <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/checked_text_view_0"
        style="?android:attr/spinnerDropDownItemStyle"
        android:singleLine="true"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:minHeight="48dp" />

</LinearLayout>

We use the above XML in a custom ArrayAdapter. The custom ArrayAdapter will then attached to Spinner

repeatInfoSpinner.setAdapter(repeatInfoArrayAdapter);

When we are using support library (Before migrating to AndroidX), it looks like this. It comes with nice touch ripple effect.

enter image description here


After migrating to AndroidX, it looks like legacy holo design.

enter image description here


It seems that, the style attribute which is previously found in support library (https://chromium.googlesource.com/android_tools/+/bf45c76e0eb23b7b7a9d5f26b28c16983daa173b/sdk/extras/android/support/v7/appcompat/res/values/themes.xml#33) , no longer found in AndroidX.


May I know, how can we resolve such, to make our app looks like material design app?

Note, I had tried ?attr/spinnerDropDownItemStyle. It makes no difference.

Upvotes: 2

Views: 767

Answers (2)

patel dhaval r
patel dhaval r

Reputation: 1297

i try simple demo in androidx

 <androidx.appcompat.widget.AppCompatSpinner
        android:id="@+id/spinner"
        android:padding="8dp"
        android:singleLine="true"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:fontFamily="sans-serif"/>

and code side simple arrayAdapter give me correct result

class MainActivity : AppCompatActivity() {

val list = listOf<String>("das","fsdfs","fsdfsd","fsdfsd")

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    spinner.adapter = ArrayAdapter(this,android.R.layout.simple_list_item_1,list)
}
}

Still problem if you have problem , please check Dialog and Activity style theme.

please look below result of mine

enter image description here

Upvotes: 2

Jack
Jack

Reputation: 5614

I was having some similar problems before, turns out you have to change the ways you refer to these styles, they are more "Object-oriented" now in AndroidX. In your case, I think you would use something like:

style="@style/Widget.AppCompat.DropDownItem.Spinner"

instead of the original:

?android:attr/spinnerDropDownItemStyle

If it doesn't resolve, remember to check your gradle file and see if androidx's appcompat dependency is there, it should be something like this:

implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'

Upvotes: 0

Related Questions