2016-05-12 66 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); 
    } 

Android清單

<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.xml' – Gaurav

+0

後你menu_main。 xml –

+0

請檢查我的文章 –

回答

0

我已經設法找到了問題,我解決了這個問題。問題是與抽屜佈局,是在content.xml中的文件我藉此抽屜,將其放置在Activity.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

有關錯誤表示函數無法覆蓋 –