有没有办法改变AlertDialog中标题下划线的颜色? 我已经通过自定义样式定义更改了标题颜色(见下文),但我没有找到下划线的任何 xml 属性。
<style name="CustomTitle" parent="@android:style/TextAppearance.Holo">
<item name="android:textColor">@color/green</item>
</style>
我运行的是 Android 4。
编辑:这就是我创建 AlertDialog 的方式
Builder ad = new AlertDialog.Builder(new ContextThemeWrapper(this,
R.style.DialogPrivate));
ad.setTitle("Custom Dialog");
ad.setMessage("blaaaaa");
ad.setPositiveButton("test", null);
ad.setNegativeButton("test2", null);
ad.show();
目前的情况如何 Screenshot
最佳答案
下划线实际上是一个 View 对象,其背景颜色设置为默认的全息蓝色(至少在 jellybean 上)。
您可以在以下位置查看警报对话框的布局:https://github.com/android/platform_frameworks_base/blob/master/core/res/res/layout/alert_dialog_holo.xml#L58 。具体来说,titleDivider View :
<View android:id="@+id/titleDivider"
android:layout_width="match_parent"
android:layout_height="2dip"
android:visibility="gone"
android:background="@android:color/holo_blue_light" />
这很不幸,因为这意味着如果没有一些丑陋的黑客代码,就无法自定义 View 的颜色,例如:
void changeUnderlineColor(AlertDialog d, int color) {
final ViewGroup v = (ViewGroup) d.getWindow().findViewById(android.R.id.content);
v.findViewById(getResources().getIdentifier("titleDivider", "id", "android")).setBackgroundColor(color);
}
这适用于使用 Holo_light 主题的 Jellybean,但几乎可以肯定这是一个坏主意。如果您确实想更改线条的颜色,看起来您需要自己构建一个完全自定义的对话框
关于android - AlertDialog标题下划线颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9239751/