如何创建操作栏上的三个均匀间隔按钮 [英] How to create three evenly spaced buttons on the action bar
问题描述
我是新android开发,我想知道我怎么可以在操作栏上创建三个均匀分布的按键,并确保他们填满了整个行动吧。
在code到目前为止,我已经写了
<?XML版本=1.0编码=UTF-8&GT?;
<菜单的xmlns:机器人=http://schemas.android.com/apk/res/android> <项目
机器人:ID =@ + ID / action_groups
机器人:showAsAction =总是
机器人:标题=@字符串/ action_groups/>
<项目
机器人:ID =@ + ID / action_list_of_contacts
机器人:showAsAction =总是
机器人:标题=@字符串/ action_listOfContacts/>
<项目
机器人:ID =@ + ID / action_favourites
机器人:showAsAction =总是
机器人:标题=@字符串/ action_favourites/>
&所述; /菜单>
您可以用做 setCustomView()
这是样品布局(sp.xml)
<?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=横向
><按钮
机器人:layout_width =0dp
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:文字=Button1的
/><按钮
机器人:layout_width =0dp
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:文字=Button1的
/>
<按钮
机器人:layout_width =0dp
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:文字=Button1的
/>< / LinearLayout中>
而在后的setContentView
活动做到这一点。
getActionBar()setHomeButtonEnabled(假)。
getActionBar()setDisplayShowCustomEnabled(真)。
getActionBar()setCustomView(R.layout.sp)。
I am new to android development and I was wondering how can I can create three evenly spaced buttons on the action bar and make sure that they fill up the whole action bar.
The code I have written so far
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_groups"
android:showAsAction="always"
android:title="@string/action_groups" />
<item
android:id="@+id/action_list_of_contacts"
android:showAsAction="always"
android:title="@string/action_listOfContacts"/>
<item
android:id="@+id/action_favourites"
android:showAsAction="always"
android:title="@string/action_favourites" />
</menu>
You can do it by using setCustomView()
this is the sample layout (sp.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="button1"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="button1"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="button1"
/>
</LinearLayout>
And in the activity after setContentView
do this
getActionBar().setHomeButtonEnabled(false);
getActionBar().setDisplayShowCustomEnabled(true);
getActionBar().setCustomView(R.layout.sp);
这篇关于如何创建操作栏上的三个均匀间隔按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!