简体   繁体   中英

Ripple effect does not work correctly on Android 9 (Api 28, Pie)

Such issue. Set the ripple effect on the button. On all versions of Android works correctly: when I press the button, it is slightly illuminated, then when I release the button, there is a small ripple. On Android 9 works half: the button is highlighted, but when the button is released, there is no ripple. Has anyone come across this? How can I fix it?

Background button - https://ru.stackoverflow.com/questions/935547/%D0%AD%D1%84%D1%84%D0%B5%D0%BA%D1%82-ripple-%D0%BD%D0%B5%D0%BA%D0%BE%D1%80%D1%80%D0%B5%D0%BA%D1%82%D0%BD%D0%BE-%D1%80%D0%B0%D0%B1%D0%BE%D1%82%D0%B0%D0%B5%D1%82-%D0%BD%D0%B0-android-9-api-28-pie

I ran into this problem and it was due to me setting the background colour to white for the preferenceTheme

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="preferenceTheme">@style/SettingsTheme</item>
</style>
<style name="SettingsTheme" parent="PreferenceThemeOverlay">
    <item name="android:background">@color/white</item>
</style>

To fix this, I removed the preferenceTheme and set the background colour as white in my preference fragment:

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    view.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.white));
}

Also update your preference code to the latest AndroidX way of doing things, eg in your prefs.xml use this:

<androidx.preference.PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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