如何Android Holo主题样式对话框button

我创build一个对话框上河洛主题和要遵循显示button的OS默认方式。 到目前为止,我所创build的对话框,但button不能在它在河洛做了ICS的应用程序的方式呈现。 我怎样才能做到这一点? 我的意图和感觉是 在这个图像中的第三 我能够到达这里 注意注册和登录按钮

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

这对我来说很好。

... <!-- 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> ... 

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

 android:theme="@android:style/Theme.Holo.Dialog" 

这是什么工作:

 <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> 

属性style="@android:style/Widget.Holo.Light.Button.Borderless.Small"给出了平坦的外观和感觉,50%的权重分布是因为将LinearLayout的100美元大小合并为android:layout_width="match_parent" and android:layout_weight =”1“`button

你可以通过Android Manifest xml设置主题,或者使用setTheme(android.R.style.Theme_Holo);在Activity的onCreate中设置主题setTheme(android.R.style.Theme_Holo);

button大小与主题本身无关。 大小取决于你的XML定义。 在你发送的图片中,button看起来好像是Holo的主题,所以这里没有错。

这是一个xml布局,它将拉伸button来填充整个对话框宽度:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" > <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="5dip" > <Button android:id="@+id/okButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="OK" /> <Button android:id="@+id/cancelButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="Cancel" /> </LinearLayout> </LinearLayout>