Android 安卓主题首选项对话框
我有一个应用程序,它使用首选项活动来设置一些用户设置。我一整天都在想这个问题。当用户按下“编辑文本首选项”对象时,我尝试设置警报对话框的主题。将打开一个对话框,用户可以设置共享首选项。弹出对话框: 我想要绿色的文本。我要绿色的。线条和光标为绿色 这就是我目前所拥有的Android 安卓主题首选项对话框,android,themes,Android,Themes,我有一个应用程序,它使用首选项活动来设置一些用户设置。我一整天都在想这个问题。当用户按下“编辑文本首选项”对象时,我尝试设置警报对话框的主题。将打开一个对话框,用户可以设置共享首选项。弹出对话框: 我想要绿色的文本。我要绿色的。线条和光标为绿色 这就是我目前所拥有的 <style name="CustomDialogTheme" parent="@android:style/Theme.Dialog"> <item name="android:background"&
<style name="CustomDialogTheme" parent="@android:style/Theme.Dialog">
<item name="android:background">@color/text_green</item>
<item name="android:textColor">@color/text_green</item>
</style>
@颜色/文本为绿色
@颜色/文本为绿色
有人能给我指出正确的方向或者分享一些代码吗。我迷路了。我一天大部分时间都在上网找东西。提前感谢。您可以使用自己的自定义组件为自己的对话框主题构建自定义布局,例如,您也可以使用外部LIB 因此,在这种情况下,用户可以根据需要自定义对话框:
<style name="DialogStyleLight.Custom">
<!-- anything can be left out: -->
<item name="titleTextColor">@color/dialog_title_text</item>
<item name="titleSeparatorColor">@color/dialog_title_separator</item>
<item name="messageTextColor">@color/dialog_message_text</item>
<item name="buttonTextColor">@color/dialog_button_text</item>
<item name="buttonSeparatorColor">@color/dialog_button_separator</item>
<item name="buttonBackgroundColorNormal">@color/dialog_button_normal</item>
<item name="buttonBackgroundColorPressed">@color/dialog_button_pressed</item>
<item name="buttonBackgroundColorFocused">@color/dialog_button_focused</item>
<item name="dialogBackground">@drawable/dialog_background</item>
</style>
@颜色/对话框\标题\文本
@颜色/对话框\标题\分隔符
@颜色/对话框\消息\文本
@颜色/对话框按钮文本
@颜色/对话框按钮分隔符
@颜色/对话框按钮\u正常
@颜色/对话框按钮按下
@颜色/对话框按钮聚焦
@可绘制/对话框背景
如果您不想创建自定义布局或使用第三方库,您可以子类化EditTextPreference
,然后使用Resources.getIdentifier
然后使用Window.findViewById
访问要编辑的每个视图。这里有一个简单的例子
public class CustomDialogPreference extends EditTextPreference {
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);
}
// EditText
final View editText = window.findViewById(android.R.id.edit);
if (editText != null) {
editText.setBackground(res.getDrawable(R.drawable.apptheme_edit_text_holo_light));
}
}
}
实施
将xml中的
替换为
注意
我曾经为EditText
创建背景
这可能有助于得出您的答案:酷。。我会试试看。。。基本上,您可以将其用于所有首选项狗类型吗?如果您想用它替换任何DialogPreference
,那么您需要将DialogPreference
子类化,而不是EditTextPreference
。我假设您基本上将该类称为<代码>
在您的首选项布局中?@user225502是的,我对我的帖子进行了编辑。到目前为止还不错。。。问题。。你在哪里学的。有一件事我正在努力与安卓系统是一个很好的参考