android - 无法在工具栏上显示后退按钮
问题描述
尽管尝试了所有技巧,包括使缓存无效等,但我无法在工具栏上显示后退按钮。因为我似乎在浪费时间在我似乎忽略的事情上,请求帮助来解决这个问题。提前致谢。我的代码如下:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DeliveryActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</com.google.android.material.appbar.AppBarLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
我的活动
package com.example.mymallapp;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.os.Bundle;
import android.view.MenuItem;
import java.util.Objects;
public class DeliveryActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_delivery);
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setTitle("Delivery");
}
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home){
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}
解决方案
谢谢大家..问题解决了..虽然后退按钮在设计选项卡上不可见,但当我在设备上运行应用程序时,它就在那里。比较意外!
推荐阅读
- .htaccess - htaccess 重定向到错误的网站/公共
- python - 使用 ForeignKey 的复杂 Django QuerySet 查询
- python - Django/DRF 后端未从 POST 请求接收完整数据
- javascript - 重试获取请求不返回任何内容
- python - 我得到'float'对象是不可迭代的,因此我使用 str 将其转换为字符串但不工作
- c - ncurses 库的问题
- sql - 使用 JOIN、GROUP BY 和 SUM 组合两个查询?
- python - 如何加入多个数据框(减少功能),将列重命名为原始数据框名称?
- mysql - mysql 上的连接被拒绝,用户在 % 上授予
- javascript - 我如何知道我的哪些依赖项正在使用导致警告的依赖项?