Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
262 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 Answer

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 :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...