52

Holoテーマでダイアログボックスを作成していて、ボタンを表示するOSのデフォルトの方法に従いたいと思います。これまでにダイアログボックスを作成しましたが、HoloforICSで実行されるアプリのようにボタンがレンダリングされません。これどうやってするの?私の意図したルックアンドフィールは この画像の3番目 ここまで到達できます サインアップボタンとログインボタンに注意してください

4

3 に答える 3

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

このレイアウトを読み込むアクティビティには、Holo.Dialog テーマが必要です。

android:theme="@android:style/Theme.Holo.Dialog"
于 2012-07-23T22:54:32.417 に答える
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>

このプロパティstyle="@android:style/Widget.Holo.Light.Button.Borderless.Small"はフラットなルック アンド フィールを提供し、50% の重量配分は、ボタンの android:layout_weight="1"` にLinearLayoutよる100$ のサイジングを組み合わせるためです。android:layout_width="match_parent" and

于 2012-03-21T17:23:32.943 に答える
2

テーマは、Androidマニフェストxmlを介して、またはアクティビティのonCreatewith内で設定できます。setTheme(android.R.style.Theme_Holo);

ボタンのサイズは、テーマ自体とは関係ありません。サイズはxml定義次第です。送信した画像では、ボタンがホロテーマを受け取っているようですので、ここでは何も問題はありません...

次に、ダイアログの幅全体にボタンを拡大する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>
于 2012-03-21T12:03:37.200 に答える