2016-04-02 11 views
0

3つのツールバーを作成しました。ツールバーの設定ボタンの項目の追加方法は?

  • ユーザーAvataar
  • タイトル
  • ic_action_overflow

私がオープン取得する必要のドロップダウンのこのリストにic_action_overflow.Whenのユーザーがクリック内の項目のいくつかのリストを追加したいです。

参照用activity.xmlを見つけてください:ツールバーのオーバーフロー・アイコン上のアイテムを追加するための

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ffffff" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    tools:context="com.example.vimal.edkul.StudentProfile"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/layout1"> 
     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="@color/red"> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="left" 
       android:src="@drawable/pic13" /> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:text="User Profile" 
       android:textSize="20sp" 
       android:textColor="@android:color/white" /> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="right" 
       android:src="@drawable/ic_action_overflow" /> 
     </android.support.v7.widget.Toolbar> 
    </LinearLayout> 
    </RelativeLayout> 
+0

あなたはスピナーを追加することができます代わりに、イメージ・ビュー(すなわち 'ic_action_overflow')の – Kathi

+0

http://wptrafficanalyzer.in/blog/adding-action-items-and-overflow-menu-items-to -action-bar-in-android/ –

+0

@Kathiありがとう。いいアイデアです。 –

答えて

0

これは動作するはず

Toolbar toolbr = (Toolbar) findViewById(R.id.toolbar); 
    toolbar.inflateMenu(R.menu.some_menu); 
    String[] items = getResources().getStringArray(R.array.menu_items); 
    for (int i = 0; i < items.length; i++) { 
     toolbar.getMenu().add(items[i]); 
    } 
関連する問題