I am using android-support-v7-appcompat.
In action, I want to show the back button in the action bar. I AM:
public class News extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.act_news_screen); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(false); } }
and
@Override public boolean onOptionsItemSelected(MenuItem item) { System.out.println(item.getItemId()); // 16908332 System.out.println(R.id.home); // 2131034132 System.out.println(R.id.homeAsUp); // 2131034117 switch(item.getItemId()) { case R.id.home: onBackPressed(); break; case R.id.homeAsUp: onBackPressed(); break; case 16908332: onBackPressed(); // it works break; default: return super.onOptionsItemSelected(item); } return true; }
If I use a numerical filter by id it works, but I think that the ID is generated by R and therefore can change, so R.id. is used. Any idea?
source share