操作欄上的菜單圖標不起作用。圖標顯示但不可點擊。我也適用不同的主題,但沒有幫助。操作欄菜單項正在顯示,但無法正常工作
風格
<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文件
添加您的'menu_main.xml' – Gaurav
後你menu_main。 xml –
請檢查我的文章 –