Я создаю диалоговое окно на тему Holo Theme и хочу следовать стандартным способам отображения кнопок на OS. Пока я создал диалоговое окно, но кнопки не отображаются так, как это делается в приложениях, выполненных в Holo для ICS. Как я могу это сделать? Мой предназначенный внешний вид и я могу добраться досюда
Как использовать кнопки диалогового окна стиля стиля головоломки Android
Ответ 1
немного поздно, но, возможно, кто-то все еще заинтересован в этом.
это работает очень хорошо для меня.
...
<!--
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"
Ответ 2
Это то, что работает:
<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% распределение веса из-за сочетания 100 $размера LinearLayout
на android:layout_width="match_parent" and
android: layout_weight = "1" `для кнопок
Ответ 3
Вы можете установить тему через Android Manifest xml или внутри Activity onCreate с помощью setTheme(android.R.style.Theme_Holo);
Размер кнопок не связан с самой темой. Размер зависит от ваших xml-определений. В изображении, который вы отправили, кажется, что кнопки получили тему Holo, поэтому здесь ничего плохого...
Здесь xml-макет, который растягивает кнопки, чтобы заполнить всю ширину диалогового окна:
<?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>