简体   繁体   English

从操作栏中删除后退箭头按钮

[英]To remove the back arrow button from Action Bar

In my Android Project, whenever I go from First Activity to Second, I get an left arrow button followed by the some text in the action bar. 在我的Android项目中,每当我从First Activity转到Second时,我会得到一个左箭头按钮,然后是操作栏中的一些文本。 That left arrow only comes when I set my First Activity as the hierarchical parent of the Second Activity. 左箭头仅在我将第一个活动设置为第二个活动的分层父级时出现。

I want to remove that back button and replace it with an icon. 我想删除该后退按钮并将其替换为图标。 I have read other posts for the same question, and so I have already tried the following code in my onCreate() method. 我已经阅读了同一个问题的其他帖子,所以我已经在onCreate()方法中尝试了以下代码。

getActionBar().setDisplayHomeAsUpEnabled(false);

But after reaching to the second activity, the app gets crashed. 但在达到第二项活动后,该应用程序崩溃了。

Please help me out. 请帮帮我。

Use getSupportActionBar() bar: 使用getSupportActionBar()栏:

getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setHomeButtonEnabled(false);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_yourindicator);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM