Toolbar menu item not clickable on android 4.4 (19) - android

I have a Android app for Android sdk version 23. Now I try to make it available for user using versions 19 to 23.
All is working fine expect the toolbar in the head of the app. I can't click an menu item. Nothing happend when I click. Also if I insert Log.v() there is no message in the debug view.
What can I do?
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) {
return true;
}
if (id == R.id.action_refresh) {
doRefreshGames(item);
return true;
}
if(id == R.id.action_rss){
Intent rssIntent = new Intent(AmericanFootball.this, AmericanFootballRSS.class);
//if you need to pass data:
Bundle mBundle = new Bundle();
mBundle.putString("myKey", "comeon");
rssIntent.putExtras(mBundle);
startActivity(rssIntent);
}
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}

I experienced this issue too. This was because I was using CoordinatorLayout which is a super-powered FrameLayout and thus was Overlaying the toolbar thus blocking interaction with the toolbar. I solved the issue by replacing the CoordinatorLayout with a LinearLayout and giving it a vertical orientation.
You can also solve the issue by setting the toolbar position in relation to the parent as described here

Related

Start Activity in same intent

i want to know how to start all my activities in same intent. My app have a drawer activity and i want when i select any item, it will start an activity in the same intent, how can i do that ?
Main Acitivy
#Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_camera) {
// Handle the camera action
} else if (id == R.id.nav_gallery) {
startActivity(new Intent(MainActivity.this, Main2Activity.class));
return true;
I checked Google Drive and I'm guessing you're referring to the behavior that when you click on something only a part of the screen updates. You can easily implement this by using Fragments. I cannot explain it to you in detail but this is a developer.google link that will help you get started. https://developer.android.com/training/basics/fragments/index.html

navigation view android not triggered onOptionsItemSelected on R.id.home

I have created the navigation drawer activity from android studio and in the method onOptionsItemSelected i'm trying to catch the click of the hamburger icon but it doesn't work.
The only thing i changed is this:
#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 == android.R.id.home) {
Log.w("ACTIVITY","home pressed");
return true;
}
return super.onOptionsItemSelected(item);
}

Back button behavior on an Activity

I have a problem in my app. I have a MainActivity with Fragments, each Fragment have a list with a recyclerView. When I click an Item of the list, the app goes to a new DetailActivity.
In the DetailActivity I have the next code line:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
When I click the back button in the ActionBar I return to the MainActivity in another fragment, not the one I clicked the item.
Thanks!
As stated by #kareem adel make sure you are not ending the previous activity. Dont use Flag_activity_clear_task or flag_activity_new_task
If that doesn't help you could just tell the back button where to go.
With getSupportActionBar().setDisplayHomeAsUpEnabled(true); set you can do this:
#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) {
return true;
}
else if(id == android.R.id.home){
//Back button was hit so go somewhere.
Intent i= new Intent(this, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); //Clear previous Activities
startActivity(i);
finish(); //End this activity.
return true;
}
return super.onOptionsItemSelected(item);
}

Android Studio Classes Could be Instantiated

content_main.xml
activity_main.xml
I was trying to following an online youtube android beginner class tutorial, but when I create a new blank activity, the 3 dot on the right top overflow menu does not show and this rendering problem happened. I've tried to change the API to 22, 21, 19 and also tried changing the style.xml method, both doesn't work for me. Please help. Thanks.
For Menu u have to override the below functions.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().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) {
return true;
}
return super.onOptionsItemSelected(item);
}
Even though menu is not available in preview,just test it in emulator or real device.It works perfectly.

Evaluating R.id.home

I was following this tutorial here - http://developer.android.com/training/implementing-navigation/ancestral.html - for implementing the Up Navigation. Sort of the same as the user pressing the Back button on the phone, but the onBackPressed() method does not fire when the 'Up' button is pressed. In the tutorial they show that you trap R.id.home in the onOptionsItemSelected() method. This web page - http://developer.android.com/reference/android/R.id.html - shows that the value of R.id.home should equal 16908332, but it doesn't in my app. In the code below if I use R.id.home it fails. If I hard-code in 16908332 it works. For me R.id.home evaluates to 21312330724. According to the page, all of the R.id values begin 1690. I hate hard-coding in a value for a built-in value, but I'm not sure what else to do. Could this cause problems down the road? Am I doing something wrong? Is this a bug?
Greg
#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) {
return true;
}
//noinspection SimplifiableIfStatement
if (id == R.id.home) {//16908332
Intent upIntent = NavUtils.getParentActivityIntent(this);
upIntent.putExtra(CAT_ID, CatID);
upIntent.putExtra(USER_ID, UserID);
upIntent.putExtra(LIST_ID, ListID);
setResult(RESULT_OK, upIntent);
NavUtils.navigateUpTo(this, upIntent);
return true;
}
return super.onOptionsItemSelected(item);
}
You need to compare it to the android one:
if (id == android.R.id.home){
...
}

Categories

Resources