2017-02-03 83 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); 
}