分频器的动作条菜单项 [英] Dividers for the actionbar menu items
问题描述
我正在开发平板电脑的Android应用程序。在这里,我得到了与操作栏菜单项UI的一个问题。
I am developing Tablet android application. Here i got one issue with the UI of the action bar menu items.
注:我使用Android原生动作条。
Note: I am using android Native actionbar.
1)如何显示菜单项之间的分隔等作为展会的形象。
我试着用除法的风格和自定义样式,但它不`吨在我的操作栏中反映。
1) How to show divider between menu items like as show in the image.
I tried with divider styles and custom styles but it doesn`t reflect in my action bar.
2)我怎么能添加多个菜单项组合成一个菜单项等作为展会的图片。
2) How can I add multiple menu items into a single menu item like as show in the picture.
我试着用自定义的布局,但溢出菜单中的项目没有显示。
我试着用的PopupMenu的溢出菜单,但图标不溢出列表中。
I tried with custom layout but overflow menu for the items is not showing.
I tried with PopupMenu for the overflow menu but the icon is not visible in overflow list.
下面我用样式的动作栏应用程序,styles.xml
Here I was using styles for the action bar application, styles.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/AppTheme.ActionBar</item>
<item name="android:textAllCaps">false</item>
<item name="android:actionMenuTextAppearance">@style/AppTheme.ActionBar.MenuTextStyle</item>
<item name="android:actionOverflowButtonStyle">@style/OverFlow</item>
<item name="android:divider">@color/dividercolor</item>
</style>
<style name="OverFlow" parent="@android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">@drawable/ic_actionbar_dots</item>
</style>
<style name="AppTheme.ActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">@drawable/actionbar_background</item>
<item name="android:height">100dip</item>
<item name="android:titleTextStyle">@style/AppTheme.ActionBar.Text</item>
<item name="android:textColor">@color/white</item>
<item name="android:divider">@drawable/divider</item>
<item name="android:showDividers">beginning</item>
<item name="android:dividerPadding">10dp</item>
</style>
<style name="AppTheme.ActionBar.MenuTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Menu">
<item name="android:textAllCaps">false</item>
<item name="android:textColor">@color/white</item>
<item name="android:textSize">26sp</item>
</style>
<style name="AppTheme.ActionBar.Text" parent="@android:style/TextAppearance">
<item name="android:textAllCaps">false</item>
<item name="android:textColor">@color/white</item>
</style>
menu.xml文件
menu.xml
<group android:id="@+id/menu_mainGroup" >
<item
android:id="@+id/connection"
android:icon="@drawable/nw_pt_calc"
android:showAsAction="always"
android:title=" ">
</item>
<item
android:id="@+id/status_menu"
android:actionLayout="@layout/application_status_overflowmenu"
android:showAsAction="ifRoom|withText">
</item>
<!--
<item
android:id="@+id/status"
android:icon="@drawable/ic_available"
android:showAsAction="always"
>
<menu>
<item
android:id="@+id/status1"
android:icon="@drawable/ic_available"
android:showAsAction="always"
android:title="@string/menu_available">
</item>
<item
android:id="@+id/status2"
android:icon="@drawable/ic_busy"
android:showAsAction="always"
android:title="@string/menu_busy">
</item>
<item
android:id="@+id/status3"
android:icon="@drawable/ic_logoff"
android:showAsAction="always"
android:title="@string/menu_logoff">
</item>
</menu>
</item>
<item
android:id="@+id/display_pic"
android:icon="@drawable/ic_person"
android:showAsAction="always">
</item>
<item
android:id="@+id/display_name"
android:showAsAction="always">
</item>
-->
<item
android:id="@+id/menu_search"
android:icon="@drawable/ic_search"
android:showAsAction="always"
android:visible="false">
</item>
<item
android:id="@+id/help"
android:icon="@drawable/ic_help"
android:showAsAction="always"
android:visible="false">
</item>
<item
android:id="@+id/about"
android:showAsAction="never"
android:title="@string/about">
</item>
<!--
<item
android:id="@+id/notification_history"
android:showAsAction="never"
android:title="@string/notification_history">
</item>
<item
android:id="@+id/comm_msg_history"
android:showAsAction="never"
android:title="@string/comm_msg_history">
</item>
-->
</group>
帮助将AP preciated。谢谢期待着听到爱好者答案:)
Help will be appreciated. Thanks looking forward to hear answers from geeks :).
推荐答案
我不知道你是否已经解决您的问题。但我可以解释一下你以防万一。
首先,在自定义分隔的动作条
,你必须要做到这一点在你的主题
与父 ActionButton
。你这样做:
I don't know if you have resolved your problem. But I can explain you just in case.
First of all, to customize the divider in your ActionBar
, you must to do this in your Theme
with the parent ActionButton
. You do this:
<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:divider">@color/dividercolor</item>
</style>
<style name="AppTheme.ActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:divider">@drawable/divider</item>
</style>
试试这个方法:
Try this way:
<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionButtonStyle">@style/ActionButton</item>
<item name="android:actionBarDivider">@color/blue</item>
<item name="actionBarDivider">@color/blue</item>
</style>
<style name="ActionButton" parent="@android:style/Widget.Holo.Light.ActionButton">
<item name="android:background">@color/blue</item>
</style>
您可以在这里阅读解决方案:无法更改的动作条分颜色有:的ActionBar菜单项分隔。
You can read the solution here: Can't change color of actionBar divider and there: ActionBar MenuItem Divider.
然后,您可以创建一个 9补丁
绘制看起来像正好在你的形象。尝试使用这样的形象:
黑色边框指明扩大你的形象。我这样做是对的左侧/右侧扩大你的分上它的高度。您可以阅读从文档画出9补丁知道如何使用在SDK中画出9修补工具
。
或者,你可以把它在XML中,类似如下:
Then, you can create a 9-Patch
drawable to look like exactly at your image. Try to use something like this image:
The black border indicate where expand your image. I did it on the left/right sides to expand your divider on its height. You can read Draw 9-patch from the Documentation to know how use the Draw 9-Patch tool
in the sdk.
Or, you can make it in xml, something like below:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- first line vertical blue -->
<item android:left="1dp">
<shape android:shape="line">
<stroke
android:color="@color/blue"
android:width="1dp" />
</shape>
</item>
<!-- second line vertical white -->
<item android:right="1dp">
<shape android:shape="line">
<stroke
android:color="@color/white"
android:width="1dp" />
</shape>
</item>
</layer-list>
在此之后,你只需要在你的 style.xml
声明为:
&LT;项目...&GT; @可绘制/ blue_divider&LT; /项目&GT;
。
After that, you just have to declare it in your style.xml
as:
<item ...>@drawable/blue_divider</item>
.
现在你有自定义分(=
Now you have customize divider (=
然后,在你的自定义布局动作条
。
这是可能做到如下:
Then, your custom layout in ActionBar
.
It's possible to do as below:
ActionBar actionBar = getActionBar();
actionBar.setCustomView(R.layout.application_status_overflowmenu);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM|
ActionBar.DISPLAY_SHOW_HOME);
和 application_status_overflowmenu.xml
将是这样的:
<RelativeLayout
android="@+id/theCustomIcon"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_gravity="right" android:gravity="center"
android:paddingLeft="10dp" android:paddingRight="10dp"
android:clickable="true" >
<ImageView
android:id="@+id/blockCustomIcon"
android:layout_width="50dp" android:layout_height="50dp"
android:src="@drawable/green_block"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true" />
<ImageView
android:id="@+id/imgCustomIcon"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/green_block"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/blockCustomIcon" />
<TextView
android:id="@+id/txtCustomIcon"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/green_block"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:gravity="left" />
</RelativeLayout>
最后,你可以有机会获得查看
s到更新项目:
TextView text = (TextView) actionBar.getCustomView().findViewById(R.id.txtCustomIcon);
text.setText("Emily Nichols");
这就是全部!
如果你的菜单选项消失,请检查您的 onCreateOptionsMenu
被夸大了良好的布局,如果它返回true。您还可以添加自定义项目的选项菜单面前还是动态添加的项目。我让你这样做你想要的。
我希望这将是有益的,它会也有帮助。
That's all!
If your menu options disappears, check if your onCreateOptionsMenu
is inflating a good layout and if it return true. You can also add the custom item in front of options menu or add item dynamically. I let you do this as you want.
I hope this will be useful and it will helpful too.
这篇关于分频器的动作条菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!