java - 如何制作顶栏?
问题描述
为什么当我编写此代码时应用程序崩溃?
Toolbar mToolbar = findViewById(R.id.scroll_top_bar);
setSupportActionBar(mToolbar);
这是xml代码
<LinearLayout 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"
android:orientation="vertical"
tools:context=".DisplayInformations">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:liftOnScroll="true">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher_background" />
<androidx.appcompat.widget.Toolbar
android:id="@+id/scroll_top_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
</LinearLayout>
这是java代码
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_informations);
Toolbar mToolbar = findViewById(R.id.scroll_top_bar);
setSupportActionBar(mToolbar);
}
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.menu_display_informations,menu);
return true;
}
“您可能会在我的问题中发现一个错误,因为我是 stack over flow 平台的新手”
解决方案
推荐阅读
- matlab - Matlab Precision只有8位?
- html - 在悬停时模拟检查器突出显示
- matlab - Matlab通过正则表达式从字符串单元格中提取
- google-cloud-firestore - Firestore 500 writes/sec per collection 限制如何在子集合组上起作用?
- javascript - 如何使用 NodeJS 合并到 MongoDB 中现有的唯一 ID?
- rust - 为 Rust 中的集合修剪输入行
- discord.js - Discord.js removerole 不是函数
- xamarin.forms - 如何使用stacklayout居中并且还取决于图像?
- dask - 使用 Apply 有条件地为 Dask Dataframe 赋值
- linux - 变量不会将值带入 bash linux 脚本