我正在尝试在偏好设置被触摸(选定)时添加涟漪效果。我通过扩展ListPreference
来自定义我的偏好设置。我已经尝试使用RippleDrawable
通过编程方式设置涟漪效果,但我没有看到动画。
这是我的自定义偏好设置类:
public class CustomListPreference extends ListPreference {
public CustomListPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomListPreference(Context context) {
super(context);
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
setCustomStyle(view);
}
private void setCustomStyle(View view) {
TextView titleView = (TextView) view.findViewById(android.R.id.title);
titleView.setTypeface(InitActivity.TYPEFACE_REGULAR);
TextView summary = (TextView) view.findViewById(android.R.id.summary);
summary.setTypeface(InitActivity.TYPEFACE_REGULAR);
//Setting the drawable here, but it doesn't work.
RippleDrawable drawable = (RippleDrawable) getContext().getResources().getDrawable(R.drawable.my_ripple_background);
view.setBackGround(drawable);
}
}
我的偏好设置布局
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<!-- opens a subscreen of settings -->
<com.abc.app.CustomListPreference
android:defaultValue="1"
android:entries="@array/sampleEntries"
android:entryValues="@array/SampleEntryValues"
android:key="some_preference"
android:title="@string/some_preferences" />
<com.abc.app.CustomCheckboxPreference
android... />
</PreferenceScreen>
我的ripple xml
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/light_black_overlay"> <!--#22000000-->
<item>
<shape
android:shape="rectangle">
<solid android:color="@android:color/background_light" />
</shape>
</item>
</ripple>
我是否为正确的视图设置了动画?感谢任何想法。谢谢。
ripple_background
和my_ripple_background
? - Tim