【问题标题】:How to customize the line in Android ICS-style dialogs如何在 Android ICS 样式对话框中自定义行
【发布时间】:2012-07-10 07:14:30
【问题描述】:

如何设置对话框标题和内容之间的蓝色分隔线(见屏幕截图)?

我更喜欢通过 xml 来实现,但如有必要,我会采用编程解决方案。

我查看了android-15的默认styles.xml和themes.xml,但是什么都找不到。

【问题讨论】:

标签: android dialog styles


【解决方案1】:

如果您使用的是 ActionBarSherlock,您可以通过查看 abs_dialog_title_holo.xml 来检查它。在那里你会看到蓝线是一个通过视图定义的分隔符:

<View android:id="@+id/abs__titleDivider"
        android:layout_width="fill_parent"
        android:layout_height="2dip"
        android:background="@color/abs__holo_blue_light" />

【讨论】:

  • 谢谢。所以如果不改变 ABS 的部分就没有办法定制这个?
【解决方案2】:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
        android:layout_height="match_parent"
    android:orientation="vertical"
    android:fitsSystemWindows="true">
    <TextView android:id="@android:id/title" style="?android:attr/windowTitleStyle"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:paddingLeft="16dip"
        android:paddingRight="16dip"
        android:gravity="center_vertical|left" 
        android:text="Dialog"
        android:textColor="@Color/blue"/>
    <View android:id="@+id/titleDivider"
            android:layout_width="match_parent"
            android:layout_height="2dip"
            android:background="@Color/blue" />
    <TextView android:id="@android:id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="16dip"
        android:paddingRight="16dip"
        android:gravity="center_vertical|left"
        android:textColor="@android:color/white" 
        android:text="Your Text"/>
</LinearLayout>

将此xml设置为类的内容,并在活动下方的清单文件中添加以下行:

 android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" 

【讨论】:

  • 我们希望保持原生 ICS 的外观,只是用不同颜色的那条线。但我想我可以基于默认的对话框布局......
  • @AkashG 你如何“将此 xml 设置为类的内容”?你指的是哪个班级?请您提供一个编码示例吗?如果你能帮我解决这个问题,我很乐意支持这个答案。
  • @PeteH 您可以通过获取新活动并在活动的 setContentView 中传递此布局来设置它。而且在我写的答案中也可以在清单文件中设置主题。您一定可以设置自己的自定义对话框。
  • @AkashG:感谢您的回复。仅供参考,我在整个应用程序中都使用 ActionBar。我可以使用一个主题选项来允许 ActionBar 自定义对话框吗? (.NoTitleBar 导致 ActionBar 出现 NPE)。
猜你喜欢
  • 2012-07-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-12
  • 2014-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多