如何Android Holo主题风格对话框按钮

kis*_*u27 52 android android-theme

我正在Holo Theme上创建一个对话框,并希望按照操作系统默认的方式显示按钮.到目前为止,我已经创建了对话框,但按钮不像在Holo for ICS中完成的应用程序那样呈现.我怎样才能做到这一点?我想要的外观和感觉是 此图片中排名第3 我能够到达这里 注意注册和登录按钮

Sim*_*ays 85

有点晚了,但也许有人仍对此感兴趣.

这对我来说非常有用.

...
<!--
EDIT: be carefull, "?android:attr/dividerHorizontal" is only supported since API 11
      just avoid it in prior OSs.
-->
<View
    android:layout_width="fill_parent"
    android:layout_height="1dip"
    android:background="?android:attr/dividerHorizontal" />
<LinearLayout 
    style="?android:attr/buttonBarStyle"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:paddingTop="0dip"
    android:paddingLeft="2dip"
    android:paddingRight="2dip"
    android:measureWithLargestChild="true">

    <Button 
        android:id="@+id/cancel"
        style="?android:attr/buttonBarButtonStyle"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@android:string/cancel"/>
    <Button 
        android:id="@+id/ok"
        style="?android:attr/buttonBarButtonStyle"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@android:string/ok"/>
</LinearLayout>
...
Run Code Online (Sandbox Code Playgroud)

加载此布局的活动需要Holo.Dialog主题.

android:theme="@android:style/Theme.Holo.Dialog"
Run Code Online (Sandbox Code Playgroud)


kis*_*u27 22

这是有效的:

<LinearLayout
    android:id="@+id/buttonHolder"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:orientation="horizontal"
    >

    <Button
        android:id="@+id/cmdSignup"
        style="@android:style/Widget.Holo.Light.Button.Borderless.Small"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/Signup" />

    <Button
        android:id="@+id/cmdLogin"
        style="@android:style/Widget.Holo.Light.Button.Borderless.Small"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/Login" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

该酒店style="@android:style/Widget.Holo.Light.Button.Borderless.Small"给出了扁平的外观和感觉,以及50%的重量分布是因为相结合的$ 100大小的LinearLayoutandroid:layout_width="match_parent" and机器人:layout_weight ="1"为`按钮

  • 你不应该直接引用样式,使用`style ="?android:attr/borderlessButtonStyle"`文档中使用的http://developer.android.com/guide/topics/ui/controls/button.html (5认同)
  • 这可能是不错的,但这需要API级别14来实现这种风格.如果向后兼容性很重要,你有解决方案吗? (2认同)