gpt4 book ai didi

Android 主题首选项对话框

转载 作者:太空宇宙 更新时间:2023-11-03 12:54:45 24 4
gpt4 key购买 nike

我有一个应用程序使用首选项 Activity 来设置一些用户设置。我整天都在想办法解决这个问题。当用户按下“编辑文本首选项”对象时,我正在尝试设置警报对话框的主题。将打开一个对话框,用户可以设置共享首选项。弹出对话框:

enter image description here

我想要绿色的文字。我想要分隔线绿色。线和光标绿色。

这就是我目前所拥有的。

<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));
}
}
}

实现

替换<EditTextPreference.../><path_to_CustomDialogPreference.../>在你的 xml 中。

注意

我用了Android Holo ColorsEditText 创建背景.

Example

关于Android 主题首选项对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22585448/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com