我正在努力在触摸(选择)偏好时添加涟漪效应。我通过扩展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>
我的波纹 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>
我是否为正确的视图设置动画?任何想法表示赞赏。谢谢。