当前位置:网站首页>Use of toolbar
Use of toolbar
2022-07-25 07:36:00 【Novice Xiaowang】
1. establish menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/addFriend"
android:icon="@drawable/addfriend"
android:orderInCategory="80"
android:title=" Add friends "
app:showAsAction="never" />
<item
android:id="@+id/newChat"
android:icon="@drawable/morechat"
android:orderInCategory="90"
android:title=" New group chat "
app:showAsAction="never" />
<item
android:id="@+id/scan"
android:icon="@drawable/scan"
android:orderInCategory="100"
android:title=" scan "
app:showAsAction="never"/>
<item
android:id="@+id/money"
android:icon="@drawable/money"
android:orderInCategory="100"
android:title=" Collection and payment "
app:showAsAction="never"/>
</menu>2.activity
Layout introduction toolbar
<androidx.appcompat.widget.Toolbar
android:background="@color/blue"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/toolbar"/>setSupportActionBar(mMainBinding.toolbar); No call, no display toolbar
getSupportActionBar().setTitle(" Ring letter app"); Set up toolbar The title of the
mMainBinding.toolbar.setOnMenuItemClickListener(listener); Set listener rewrite onCreateOptionsMenu load menu
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.toolbar, menu);
return true;
} rewrite onPrepareOptionsPanel load menu The icon
@Override
protected boolean onPrepareOptionsPanel(View view, Menu menu) {
if (menu != null) {
if (menu.getClass() == MenuBuilder.class) {
try {
Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
m.setAccessible(true);
m.invoke(menu, true);
} catch (Exception e) {
}
}
}
return super.onPrepareOptionsPanel(view, menu);
}Monitor
private final Toolbar.OnMenuItemClickListener listener = new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.addFriend:
Toast.makeText(MainActivity.this, "addFriend", Toast.LENGTH_SHORT).show();
break;
case R.id.scan:
Toast.makeText(MainActivity.this, "scan", Toast.LENGTH_SHORT).show();
break;
case R.id.newChat:
Toast.makeText(MainActivity.this, "newChat", Toast.LENGTH_SHORT).show();
// Pop up custom popWindow
//popUpMyOverflow();
break;
case R.id.money:
Toast.makeText(MainActivity.this, "money", Toast.LENGTH_SHORT).show();
break;
}
return false;
}
};边栏推荐
- Ask the bosses: MySQL CDC stores configuration data, and Kafka has history
- A fast method of data set enhancement for deep learning
- Robot Framework移动端自动化测试----01环境安装
- Introduction to Manhattan distance
- 【Unity入门计划】界面介绍(1)-Scene视图
- 新库上线| CnOpenDataA股上市公司股东信息数据
- 【程序员2公务员】三、资源搜集
- 线代(矩阵‘)
- The application of for loop and if judgment statement
- [cloud native] the ribbon is no longer used at the bottom of openfeign, which started in 2020.0.x
猜你喜欢

BOM overview

list的模拟实现

冰冰学习笔记:类与对象(上)

Robot Framework移动端自动化测试----01环境安装

深度学习之快速实现数据集增强的方法

QT6 with vs Code: compiling source code and basic configuration

9 best engineering construction project management systems

Have you got the advanced usage of pytest?
![[unity introduction plan] interface Introduction (2) -games view & hierarchy & Project & Inspector](/img/b0/ef084f4391795a1369b0f46a2de8d6.png)
[unity introduction plan] interface Introduction (2) -games view & hierarchy & Project & Inspector

Use cyclegan to train self-made data sets, popular tutorials, and get started quickly
随机推荐
J1 常用的DOS命令(P25)
【论文笔记】Next-ViT: Next Generation Vision Transformer for Efficient Deployment in Realistic Industrial
【程序员2公务员】四、常见问题
Million level element optimization: real-time vector tile service based on PG and PostGIS
一日千里,追风逐月 | 深势科技发布极致加速版分子对接引擎Uni-Docking
toolbar的使用
How to do a good job in safety development?
A fast method of data set enhancement for deep learning
做好项目管理的10个关键点和5大措施
Delete in elasticserach_ by_ What is the mechanism of query?
Matlab self programming series (1) -- angular distribution function
When providing digital talent services, Xi Zhi quickly opened its own digital school for each organization
New functions of shixizhi are online. These new functions are online in June. Can you use them?
Room database migration
Use cyclegan to train self-made data sets, popular tutorials, and get started quickly
[wechat applet] global style, local style, global configuration
NLP hotspots from ACL 2022 onsite experience
New version 8.6 SEO quick release system (can be built at source level)
Paddlepaddle 34 adjust the layer structure and forward process of the model (realize the addition, deletion, modification and forward modification of the layer)
"Game illustrated book": a memoir dedicated to game players