
我完全按照http://www.lukehorvat.com/blog/android-seekbardialogpreference中说明的方式实现了DialogPreference
另外,我能够更改DialogPreference的文本和分隔符颜色,但是当按钮被按下时,我无法更改其突出显示颜色.有人知道怎么做这个吗?
更新:
我对DialogPreference使用以下布局:
<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:orIEntation="vertical"><TextVIEw androID:ID="@+ID/text_dialog_message" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_margintop="6dip" androID:paddingleft="12dip" androID:paddingRight="12dip"/><TextVIEw androID:ID="@+ID/text_progress" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_margintop="6dip" androID:gravity="center_horizontal"/><Seekbar androID:ID="@+ID/seek_bar" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_marginBottom="6dip" androID:layout_margintop="6dip"/></linearLayout>到目前为止,与该DialogPreference或我更改的布局有关的唯一样式属性是通过编程方式更改的:
int alertTitleID = this.getContext().getResources().getIDentifIEr("alertTitle", "ID", "androID"); TextVIEw alertTitle = (TextVIEw) getDialog().getwindow().getDecorVIEw().findVIEwByID(alertTitleID); alertTitle.setTextcolor(color); // change Title text color int TitledivIDerID = this.getContext().getResources().getIDentifIEr("TitledivIDer", "ID", "androID"); VIEw TitledivIDer = getDialog().getwindow().getDecorVIEw().findVIEwByID(TitledivIDerID); TitledivIDer.setBackgroundcolor(color); // change divIDer color解决方法:
您需要做的只是DialogPreference的子类,然后调用Resource.getIDentifIEr来定位要主题化的每个VIEw,就像您在做的一样,但是您不需要调用Window.getDecorVIEw.这是一个例子:
自定义DialogPreference
public class CustomDialogPreference extends DialogPreference { public CustomDialogPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public CustomDialogPreference(Context context, AttributeSet attrs) { super(context, attrs); } /** * {@inheritDoc} */ @OverrIDe protected voID showDialog(Bundle state) { super.showDialog(state); final Resources res = getContext().getResources(); final Window window = getDialog().getwindow(); final int green = res.getcolor(androID.R.color.holo_green_dark); // Title final int TitleID = res.getIDentifIEr("alertTitle", "ID", "androID"); final VIEw Title = window.findVIEwByID(TitleID); if (Title != null) { ((TextVIEw) Title).setTextcolor(green); } // Title divIDer final int TitledivIDerID = res.getIDentifIEr("TitledivIDer", "ID", "androID"); final VIEw TitledivIDer = window.findVIEwByID(TitledivIDerID); if (TitledivIDer != null) { TitledivIDer.setBackgroundcolor(green); } // button vIEws window.findVIEwByID(res.getIDentifIEr("button1", "ID", "androID")) .setBackgroundDrawable(res.getDrawable(R.drawable.your_selector)); window.findVIEwByID(res.getIDentifIEr("button2", "ID", "androID")) .setBackgroundDrawable(res.getDrawable(R.drawable.your_selector)); window.findVIEwByID(res.getIDentifIEr("button3", "ID", "androID")) .setBackgroundDrawable(res.getDrawable(R.drawable.your_selector)); }}XML首选项
<PreferenceScreen xmlns:androID="http://schemas.androID.com/apk/res/androID" > <path_to.CustomDialogPreference androID:dialogMessage="Message" androID:negativebuttonText="Cancel" androID:positivebuttonText="Okay" androID:title="Title" /></PreferenceScreen>自定义选择器
<?xml version="1.0" enCoding="utf-8"?><selector xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:autoMirrored="true"> <item androID:drawable="@drawable/your_pressed_drawable" androID:state_pressed="true"/> <item androID:drawable="@drawable/your_default_drawable"/></selector>备用选择器
<?xml version="1.0" enCoding="utf-8"?><selector xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:autoMirrored="true"> <item androID:drawable="@color/your_pressed_color" androID:state_pressed="true"/> <item androID:drawable="@color/your_default_color/></selector>屏幕截图
总结以上是内存溢出为你收集整理的android-更改“ DialogPreference”的突出显示颜色(按钮颜色)全部内容,希望文章能够帮你解决android-更改“ DialogPreference”的突出显示颜色(按钮颜色)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)