我有一个使用首选项活动来设置某些用户设置的应用程序。我一整天都在试图解决这个问题。当用户按下“编辑文本首选项”对象时,我尝试为警报对话框设置主题。将打开一个对话框,用户可以设置共享首选项。弹出对话框:
我想要绿色的文字。我想要绿色的分隔线。线条和光标呈绿色。
这是我到目前为止所拥有的。
<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>
有人可以指出我正确的方向或者分享一些代码吗?我迷路了。我一整天都在上网寻找东西。提前致谢。
如果您不想创建自定义布局或使用第三方库,您可以子类化EditTextPreference
,然后访问每个View
你想使用编辑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));
}
}
}
执行
Replace <EditTextPreference.../>
with <path_to_CustomDialogPreference.../>
在你的xml中。
Note
I used Android 全息颜色来创建背景EditText
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)