Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
259 views
in Technique[技术] by (71.8m points)

android - How to Place ActionBar Items in Main ActionBar and Bottom Bar

enter image description here

The Google+ app has a layout where it has action bar items in the main action bar and the bottom. Currently I am using android:uiOptions="splitActionBarWhenNarrow" to place items in the bottom bar. How can I place items on both the top and bottom?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Hope my answer is not too late for you.

  1. Use android:uiOptions="splitActionBarWhenNarrow" (this adds stuff into bottom bar).
  2. Create new layout like the below code (this layout will handle all your items on the top bar).

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="right" >
    <Switch
        android:id="@+id/switch1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"/>
    <ImageButton
        android:id="@+id/action_starred"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="?android:attr/actionButtonStyle"
        android:src="@android:drawable/ic_menu_compass" 
        android:onClick="FakeMenu"/>
    </LinearLayout>
    
  3. Paste this in your activity

    ActionBar actionBar = getActionBar();               
    actionBar.setCustomView(R.layout.actionbar_top); //load your layout
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME|ActionBar.DISPLAY_SHOW_CUSTOM); //show it 
    
  4. That's all :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...