从支持库迁移到AndroidX后,缺少某些样式属性

问题描述 投票:2回答:2

通过引用qazxsw poi和qazxsw poi

目前,我们有以下下拉视图项。它使用风格https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/layout/simple_spinner_item.xml

https://pep-security.lu/gitlab/android/pep/blame/2f5b1397ba73f78f49f2094b9fb370d2fee62635/k9mail/src/main/res/layout/simple_spinner_item.xml

我们在自定义?android:attr/spinnerDropDownItemStyle中使用上述XML。然后定制的<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> 将附加到ArrayAdapter

ArrayAdapter

当我们使用支持库时(在迁移到AndroidX之前),它看起来像这样。它具有良好的触摸波纹效果。

Spinner


迁移到AndroidX后,它看起来像传统的全息设计。

repeatInfoSpinner.setAdapter(repeatInfoArrayAdapter);


看起来,先前在支持库(enter image description here)中找到的style属性在AndroidX中不再存在。


我可以知道,我们如何才能解决这个问题,使您的应用看起来像素材设计应用?

注意,我曾尝试过enter image description here。没什么区别。

android androidx
2个回答
1
投票

我在android中尝试简单的演示

https://chromium.googlesource.com/android_tools/+/bf45c76e0eb23b7b7a9d5f26b28c16983daa173b/sdk/extras/android/support/v7/appcompat/res/values/themes.xml#33

和代码端简单的arrayAdapter给我正确的结果

?attr/spinnerDropDownItemStyle

如果您有问题仍然有问题,请检查对话框和活动样式主题。

请看下面的结果

<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"/>


0
投票

我以前遇到过类似的问题,事实证明你必须改变你引用这些风格的方式,现在它们在AndroidX中更加“面向对象”。在你的情况下,我认为你会使用类似的东西:

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)
}
}

而不是原来的:

enter image description here

如果它没有解决,记得检查你的gradle文件,看看androidx的appcompat依赖是否存在,它应该是这样的:

style="@style/Widget.AppCompat.DropDownItem.Spinner"
© www.soinside.com 2019 - 2024. All rights reserved.