android– 对齐optionsmenu的项目(在ActionBar中)

android– 对齐optionsmenu的项目(在ActionBar中),第1张

概述我想在左边的我的选项菜单中对齐一个菜单项,正如您在contacts-app中看到的那样(编辑联系人时).我该怎么办?我是否必须更改您的xml属性或在Java代码中执行此 *** 作?最好的祝福,rnng解决方法:我从here查找了contacts-app的源代码.代码说我必须使用这个XML代码为ActionBar创建一个自定

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

最好的祝福,
rnng

解决方法:

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

代码说我必须使用这个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"            >            <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"                 />        </linearLayout>    </linearLayout></FrameLayout>

这个Java代码在这里:

 // Inflate a custom action bar that contains the "done" button for saving changes    // to the contact    LayoutInflater inflater = (LayoutInflater) getSy@R_403_6563@Service                    (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中)所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1109837.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存