I am trying to manually implement the actions that should be performed when I click the up button on the action bar, but for some reason nothing happens when I click on it.
here is my code:
public class ActivityOne extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_activity_one); Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar_actionbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); Button button = (Button)findViewById(R.id.btn1); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { openActivityTwo(); } }); Button button2 = (Button)findViewById(R.id.btn2); button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { openActivityThree(); } }); } void openActivityTwo(){ Intent intent = new Intent(this, ActivityTwo.class); startActivity(intent); } void openActivityThree(){ Intent intent = new Intent(this, ActivityThree.class); startActivity(intent); } @Override public boolean onCreateOptionsMenu(Menu menu) {
I understand that I need to explicitly assign a parent action for the activity , I want to implement navigation on the manifest file , but the problem is that there are several parents in this activity, so I thought t21>, when the up button is pressed on this operation, it will better approach.
I have already tried both id == R.id.home and id == R.id.homeAsUp , and both of them do not work. I do not know if this is because I use AppCompactActivity or what to help
java android android-activity android-studio r.java-file
spongyboss Aug 11 '15 at 11:05 2015-08-11 11:05
source share