Android   发布时间:2022-04-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 对齐optionsmenu的项目(在ActionBar中)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

我想在左边的我的选项菜单中对齐一个菜单项,正如您在contacts-app中看到的那样(编辑联系人时).我该怎么办?我是否必须更改您的xml属性或在Java代码中执行此操作?

最好的祝福,
rnng

解决方法:

我从here查找了contacts-app的源代码.

代码说我必须使用这个XML代码为ActionBar创建一个自定义布局:

<FrameLayout
    xmlns:android="http://scheR_560_11845@as.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);

使用了以下文件

> android / platform/packages/apps/Contacts / ics-mr1-release / . / src / com / android / contacts / activities / ContactEditorActivity.java
> android / platform/packages/apps/Contacts / ics-mr1-release / . / res / layout / editor_custom_action_bar.xml

大佬总结

以上是大佬教程为你收集整理的android – 对齐optionsmenu的项目(在ActionBar中)全部内容,希望文章能够帮你解决android – 对齐optionsmenu的项目(在ActionBar中)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: