如何在Material Design中创建后退按钮

mas*_*php 8 android button android-actionbar

我找不到有关在Material Design的Action栏中添加此按钮的教程.

示例图片

如何将其添加到Lollipop的操作栏中?

Tom*_*esh 18

试试这个

在创建:

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Run Code Online (Sandbox Code Playgroud)

在您的活动类中(假设您要关闭此活动)

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        finish();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}
Run Code Online (Sandbox Code Playgroud)


Har*_*rry 13

材料设计教程 这将简要介绍如何实现材料应用程序.

如果您使用的是ActionBarActivityAppCompat Theme使用:

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Run Code Online (Sandbox Code Playgroud)

您也可能需要以setHomeButtonEnabled(true)同样的方式打电话.它看起来像这样:

在此输入图像描述