3

連絡先アプリ (連絡先の編集中) でわかるように、左側のオプション メニューから 1 つのメニュー項目を揃えたいと思います。私は何をしなければなりませんか?xml 属性を変更する必要がありますか、それとも Java コードで行う必要がありますか?

よろしくお願いします。

連絡先 (編集) アクティビティのスクリーンショット

4

2 に答える 2

4

contact-app のソースコードはhereから調べました。

このコードは、次の XML コードを使用して ActionBar のカスタム レイアウトを作成する必要があることを示しています。

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/save_menu_item"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:divider="?android:attr/dividerVertical"
        android:showDividers="end"
        android:dividerPadding="12dip"
        android:orientation="horizontal">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:duplicateParentState="true"
            style="?android:attr/actionButtonStyle">

            <ImageView
                android:id="@+id/icon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginRight="8dip"
                android:src="@drawable/ic_menu_done_holo_dark"
                android:description="@string/menu_done" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginRight="20dip"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="@color/action_bar_button_text_color"
                android:text="@string/menu_done"
                style="@android:style/Widget.Holo.ActionBar.TabText" />

        </LinearLayout>

    </LinearLayout>

</FrameLayout>

そして、この Java コードは次のとおりです。

 // Inflate a custom action bar that contains the "done" button for saving changes
    // to the contact
    LayoutInflater inflater = (LayoutInflater) getSystemService
                    (Context.LAYOUT_INFLATER_SERVICE);
    View customActionBarView = inflater.inflate(R.layout.editor_custom_action_bar, null);
    View saveMenuItem = customActionBarView.findViewById(R.id.save_menu_item);
    saveMenuItem.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        mFragment.doSaveAction();
    }
    // Show the custom action bar but hide the home icon and title
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
                    ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME |
                    ActionBar.DISPLAY_SHOW_TITLE);
    actionBar.setCustomView(customActionBarView);

次のファイルが使用されました。

于 2012-06-21T19:08:34.700 に答える
2

ActionModeこれは、左側のチェックマークオンボタンを含む、この種の外観を持つを使用している可能性があります。

または、これはon 属性を使用setDisplayUseLogoEnabled()している可能性があります。android:logo<application>

または、これはカスタム UI を使用しており、通常のアクション バーを使用していない可能性があります。

于 2012-06-21T15:35:18.033 に答える