2016-05-12 12 views
0

アクションバーのメニューアイコンが機能しません。アイコンは表示されていますが、クリックできません。私は別のテーマを適用するが、役に立たない。アクションバーのメニュー項目が表示されていても機能していません。

スタイル

<resources> 

    <!-- Base application theme. --> 
    <!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
     <item name="android:windowActionBar">false</item> 
     <item name="android:windowNoTitle">true</item> 
    </style> 

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> 

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.ActionBar" /> 
</resources> 

私の主な活動

public class MainActivity extends AppCompatActivity implements View.OnClickListener { 

private TextView time,fajar,zahr,asar,magrib,isha,jumma; 
    private TextView namaz,hadith,khatam_e_nubuwat,setting; 
    DrawerLayout drawerLayout; 
    Toolbar toolbar; 
    private ActionBarDrawerToggle actionBarDrawerToggle; 

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

     toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 

     getSupportActionBar().setDisplayShowHomeEnabled(true);/// this line giving null point exception.. 
     getSupportActionBar().setDisplayUseLogoEnabled(true); 


     drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); 

     FindElement(); 
     SetClick(); 
     drawerIcon(); 

    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     MenuInflater menuInflater = getMenuInflater(); 
     menuInflater.inflate(R.menu.menu_main, menu); 



     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 

     int id = item.getItemId(); 


     //noinspection SimplifiableIfStatement 
     if (id == R.id.action_settings) { 
      Log.d("111111111", "onOptionsItemSelected: "); //// this is the menu item which is not working also drawer icon is not working.... 
      return true; 
     } 

     return super.onOptionsItemSelected(item); 
    } 

アンドロイドマニフェスト

<application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@android:style/Theme.Holo.Light.DarkActionBar" > 
     <activity 
      android:name=".SliderViewPager" 
      android:label="@string/app_name" 
      android:theme="@style/AppTheme"> 
      <!--android:noHistory="true">--> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:name=".MainActivity" 
      android:theme="@style/AppTheme"/> 
    </application> 

これは私のmenu.xmlファイルです

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    tools:context="com.example.amir.namaztimer.MainActivity"> 
    <item 
     android:id="@+id/action_settings" 
     android:orderInCategory="100" 
     android:title="@string/action_settings" 
     app:showAsAction="ifRoom" 
     android:enabled="true" 
     /> 

</menu> 

私は私のコードを更新し、私は問題を見つけるために管理していると私はそれを解決しmenu.xml

+0

は、あなたがあなたのmenu_main 'menu_main.xml' – Gaurav

+0

ポストを追加します。 xml –

+0

私のポストを確認してください –

答えて

0

が含まれます。問題....私はこの引き出しを取り、Activity.xmlに配置し、問題解決content.xmlファイルにあった引き出しのレイアウトとした

<android.support.v4.widget.DrawerLayout 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

     <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:theme="@style/AppTheme.AppBarOverlay"> 

       <android.support.v7.widget.Toolbar 
        android:id="@+id/toolbar" 
        android:layout_width="match_parent" 
        android:layout_height="?attr/actionBarSize" 
        android:background="?attr/colorPrimary" 
        app:popupTheme="@style/AppTheme.PopupOverlay" /> 

     </android.support.design.widget.AppBarLayout> 

     <include layout="@layout/content_main" /> 

    </FrameLayout> 
0
@Override 
    public boolean onMenuItemSelected(int featureId, MenuItem item) { 

     int itemId = item.getItemId(); 
     switch (itemId) { 
     case android.R.id.home: 
    Toast.makeText(this, "You Pressed home button",Toast.LENGTH_LONG).show(); 
      break;} 
     return true; 
    } 
+0

に関連しています –

関連する問題