2016-05-14 15 views
0

ImageButtonTextViewandroid.support.v7.widget.Toolbarに定義されています。メニュー項目もありますが、アプリを実行すると表示されません。Androidツールバー私がいるときに表示されないメニュー項目

私はこのアクティビティでgetMenuInflater().inflate(R.menu.menu, menu)をクローズしましたが、ここでは何が欠けているのか分かりません。ここで

は私tool_bar.xml次のとおりです。ここで

<android.support.v7.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="80dp" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:background="@color/colorPrimary" 
    android:id="@+id/tool_bar"> 

    <ImageButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ic_nav_icon"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/app_name" 
     android:textSize="30dp" 
     android:layout_marginLeft="20dp" 
     android:textColor="#ffffff"/> 

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

は私のメニュー項目である:

<menu 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto"> 

    <item 
     android:icon=" @drawable/ic_search" 
     android:title="Search" 
     app:showAsAction="always" /> 

</menu> 

そして、ここでは私のHomeActivity.javaクラス

private Toolbar toolbar; 

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

    toolbar = (Toolbar)findViewById(R.id.tool_bar); 
    this.setSupportActionBar(toolbar); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    getMenuInflater().inflate(R.menu.menu, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem menuItem) 
{ 
    //implement logic here to get selected item 
    return super.onOptionsItemSelected(menuItem); 
} 

なぜメニュー項目が表示されていないのですか?

+0

を変更、これを試してください:「=テーマ@android:style/ThemeOverlay.Material.Dark.ActionBar " –

+0

これはAPIレベルが必要です21 –

+0