我需要覆盖哪些主题属性才能更改对话框的蓝色突出显示颜色?

Geo*_*rge 11 android android-theme

我有一个名为"greenhighlight"的主题 - 这个主题是使用Android Action Bar Style Generator生成的,并且继承自默认的ActionBarSherlock主题.除了将ActionBar底部的突出显示从蓝色更改为绿色外,该主题不执行任何操作.

为了主题我的所有活动,我只是这样做:

<application android:theme="@style/Theme.greenhighlight"...
Run Code Online (Sandbox Code Playgroud)

这非常适合活动(请注意ActionBar底部的绿色突出显示):

主题Android活动

但是,我难以将对话框与我的活动相匹配:

默认主题Android列表对话框

默认主题Android进度对话框

我的"greenhighlight_Dialog"主题定义为:

<style name="greenhighlight_Dialog" parent="@style/Theme.Sherlock.Dialog">
    <item name="android:progressBarStyleHorizontal">
        @style/greenhighlight_ProgressBar
    </item>
</style>
Run Code Online (Sandbox Code Playgroud)

我将继承默认的Sherlock对话框主题,并使用我生成的"greenhighlight"主题定义的进度条样式覆盖进度条 - 您可以在上面的屏幕截图中看到进度条是正确的绿色阴影.

要使用主题,我运行以下代码:

ContextThemeWrapper ctw = 
    new ContextThemeWrapper(this, R.style.greenhighlight_Dialog);
AlertDialog.Builder builder = new AlertDialog.Builder(ctw);
...
ProgressDialog pd = new ProgressDialog(this, R.style.greenhighlight_Dialog);
...
Run Code Online (Sandbox Code Playgroud)

我的问题是我不知道我需要覆盖哪些属性.我一直在寻找Styles和Themes doco 推荐的styles.xmlthemes.xml(它注意到"R.style引用,但是没有很好地记录并且没有完整地描述样式") - 但是那里在Theme.Dialog上定义了很多样式,我不确定我需要覆盖哪些样式才能获得我想要的更改.

我需要覆盖哪些属性才能使我的对话框具有绿色标题文本,标题下方的绿色高亮条以及选中列表项的绿色复选标记?

Jas*_*son 23

我去挖掘源代码并遇到了alert_dialog_holo.xml布局文件.这是分隔符视图:

<View android:id="@+id/titleDivider"
    android:layout_width="match_parent"
    android:layout_height="2dip"
    android:visibility="gone"
    android:background="@android:color/holo_blue_light" />
Run Code Online (Sandbox Code Playgroud)

AlertController课堂上,VISIBLE如果存在标题,则将其可见性设置为.由于颜色是硬编码的,因此无法用style属性覆盖它.

这是标题视图:

<com.android.internal.widget.DialogTitle android:id="@+id/alertTitle"
    style="?android:attr/windowTitleStyle"
    android:singleLine="true"
    android:ellipsize="end"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
Run Code Online (Sandbox Code Playgroud)

所以它使用了windowTitleStyle.它花了很多追逐,但我最终找到了使用的风格:

<style name="TextAppearance.Holo.DialogWindowTitle">
    <item name="android:textSize">22sp</item>
    <item name="android:textColor">@android:color/holo_blue_light</item>
</style>
Run Code Online (Sandbox Code Playgroud)

继父样式之后,我只能通过样式更改文本颜色:

<style name="AppTheme" parent="@android:style/Theme.Holo">
    <item name="android:alertDialogTheme">@style/AlertDialogStyle</item>
</style>

<style name="AlertDialogStyle" parent="@android:style/Theme.Holo.Dialog">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
    <item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
    <item name="android:windowTitleStyle">@style/DialogWindowTitle</item>
</style>

<style name="DialogWindowTitle">
    <item name="android:maxLines">1</item>
    <item name="android:scrollHorizontally">true</item>
    <item name="android:textAppearance">@style/DialogWindowTitleAppearance</item>
</style>

<style name="DialogWindowTitleAppearance" parent="@android:style/TextAppearance.Holo.DialogWindowTitle">
    <item name="android:textColor">#00ff00</item>
</style>
Run Code Online (Sandbox Code Playgroud)

现在对于分隔符,你不能通过样式来改变它,但是因为你知道了id,所以你可以AlertDialog在创建它的布局(onCreate)并改变它的颜色时扩展它并拦截它.虽然这是在私人AlertController班级处理的,但我不确定你会有多少运气.如果我拿出任何东西,我会更多地研究它并回来.

  • @nilkash我只为警报对话框做了这个,但这就是我做的.首先创建一个布局,用作对话框的自定义消息[示例](http://pastebin.com/hPU2BH2W).然后扩展AlertDialogBu​​ilder类,以便在设置标题或图标时更新自定义布局而不是图标和标题属性[示例](http://pastebin.com/zpVbR7Dw).然后你就可以在像这样的代码中使用它[例子](http://pastebin.com/YnHE085i) (3认同)