2017-02-03 66 views

回答

0

您可以簡單地使用工具欄作爲操作欄。 工具欄是一個ViewGroup,您可以爲其添加任何自定義視圖。

例如:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
android:orientation="vertical"> 

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:minHeight="?attr/actionBarSize" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:titleTextColor="@android:color/white" 
    android:background="?attr/colorPrimary"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <YourViewHere/> 

    </LinearLayout> 

</android.support.v7.widget.Toolbar> 

,並在您的活動:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_my); 

    // Find the toolbar view inside the activity layout 
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    // Sets the Toolbar to act as the ActionBar for this Activity window. 
    // Make sure the toolbar exists in the activity and is not null 
    setSupportActionBar(toolbar); 
}