如何改变菜单栏“没有广告”图标在按下按钮在android工作室?

gopyfrb3  于 2021-07-11  发布在  Java
关注(0)|答案(0)|浏览(156)

有人能帮我在android studio中更改按钮中的菜单栏“无广告”图标吗?为此,我使用mainactivity和mainactivity\u no\u ads activity,对吗?我用了这些密码。

//MainActivity

     @Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater menuInflater= getMenuInflater();
    menuInflater.inflate(R.menu.menufile,menu);
    return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    switch (item.getItemId()) {
        case R.id.item1:
            Toast.makeText(this, "Settings selected", Toast.LENGTH_SHORT).show();
            Intent settings = new Intent(this, SettingsActivity.class);
            startActivity(settings);
            break;
        case R.id.item2:
            Toast.makeText(this, "You have Latest Updates", Toast.LENGTH_SHORT).show();
            break;

        case R.id.notification_bell_morning:
            //Toast.makeText(this,"Notification selected",Toast.LENGTH_SHORT).show();

            if (!flagChange ) {
                item.setIcon(R.drawable.bell);
                flagChange = true;
                Toast.makeText(this, "Time not set", Toast.LENGTH_SHORT).show();

            } else  {
                item.setIcon(R.drawable.bellnotify);
                flagChange = false;
                // Toast.makeText(this,"Time set",Toast.LENGTH_SHORT).show();

                Calendar calendar = Calendar.getInstance();
                calendar.set(Calendar.HOUR_OF_DAY, 17);
                calendar.set(Calendar.MINUTE, 30);
                calendar.set(Calendar.SECOND, 0);

                Intent intent = new Intent(MainActivity.this, ReminderBroadcast.class);
                PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 100, intent, PendingIntent.FLAG_UPDATE_CURRENT);
                AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
                alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmManager.INTERVAL_DAY, pendingIntent);

                Toast.makeText(MainActivity.this, "Reminder set at 5.30 pm", Toast.LENGTH_SHORT).show();

            }

            break;

        case R.id.notification_bell_evening:
            //Toast.makeText(this,"Notification selected",Toast.LENGTH_SHORT).show();

            if (!flagChange) {
                item.setIcon(R.drawable.bell);
                flagChange = true;
                Toast.makeText(this, "Time not set", Toast.LENGTH_SHORT).show();

            } else {
                item.setIcon(R.drawable.bellnotify);
                flagChange = false;
                // Toast.makeText(this,"Time set",Toast.LENGTH_SHORT).show();

                Calendar calendar = Calendar.getInstance();
                calendar.set(Calendar.HOUR_OF_DAY, 5);
                calendar.set(Calendar.MINUTE, 30);
                calendar.set(Calendar.SECOND, 0);

                Intent intent = new Intent(MainActivity.this, ReminderBroadcast.class);
                PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 100, intent, PendingIntent.FLAG_UPDATE_CURRENT);
                AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
                alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmManager.INTERVAL_DAY, pendingIntent);

                Toast.makeText(MainActivity.this, "Reminder set at 5.30 am", Toast.LENGTH_SHORT).show();

            }

            break;

        case R.id.no_ads:

            Toast.makeText(this, "Premium selected", Toast.LENGTH_SHORT).show();
            Intent premium = new Intent(this, Premium.class);
            startActivity(premium);

            break;

        default:return super.onOptionsItemSelected(item);
    }

    return false;
}

主活动没有广告是相同和不同的只是下面的代码片段不存在

case R.id.no_ads:

            Toast.makeText(this, "Premium selected", Toast.LENGTH_SHORT).show();
            Intent premium = new Intent(this, Premium.class);
            startActivity(premium);

            break;

我增加了阶级继承权的形象。
类层次结构

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题