当前位置:网站首页>Systemui qsSetting添加新图标
Systemui qsSetting添加新图标
2022-08-04 12:28:00 【纵容_伊人倩影】
参考文章
https://blog.csdn.net/h1217256980/article/details/105726771
补充
按照文章中的可以实现效果,本文针对第一点自定义类做一些细化。
新增按钮其实比较简单,因为原生框架已经搭建好了,我们只要集成实现关键方法就可以了。
QS添加按钮主要注意以下己点:
1、按钮状态(打开、关闭、不可用)
2、点击事件
3、长按事件
4、状态更新
西瓜桶
------因为这一天同事请我喝了一杯西瓜桶奶茶,刚好我在做添加新按钮,所以这个demo就叫这个名字了~!哈哈哈
demo代码仅供参考,因为Android大版本不同,构造方法和实现父类方法可能有一些区别。
package com.android.systemui.qs.tiles;
import android.content.Intent;
import android.graphics.Color;
import android.media.AudioManager;
import android.service.quicksettings.Tile;
import com.android.systemui.plugins.qs.QSTile;
import com.android.systemui.qs.QSHost;
import com.android.systemui.qs.tileimpl.QSTileImpl;
import javax.inject.Inject;
public class XiGuaTong extends QSTileImpl<QSTile.BooleanState> {
int index = 0;
int[] color = {
Color.BLUE,Color.DKGRAY,Color.YELLOW};
@Inject
protected XiGuaTong(QSHost host) {
super(host);
}
@Override
public BooleanState newTileState() {
BooleanState state = new BooleanState();
state.label = this.getClass().getSimpleName();
state.handlesLongClick = false;
return state;
}
@Override
protected void handleClick() {
index++;
refreshState();
}
@Override
protected void handleUpdateState(BooleanState state, Object arg) {
state.state = index%4 == 3? Tile.STATE_INACTIVE: Tile.STATE_ACTIVE;
state.secondaryLabel = String.valueOf(index);
state.label = this.getClass().getSimpleName();
switch (index%4) {
case 0:
state.icon = new DrawableIcon(mContext.getDrawable(com.android.systemui.R.drawable.ic_volume_ringer));
break;
case 1:
state.icon = new DrawableIcon(mContext.getDrawable(com.android.systemui.R.drawable.ic_volume_ringer_vibrate));
break;
case 2:
state.icon = new DrawableIcon(mContext.getDrawable(com.android.systemui.R.drawable.ic_volume_ringer_mute));
break;
case 3:
break;
default:
break;
}
// int color = this.color[index%3];
}
@Override
public int getMetricsCategory() {
return 0;
}
@Override
public Intent getLongClickIntent() {
//
return null;
}
@Override
public CharSequence getTileLabel() {
return this.getClass().getSimpleName();
}
}
疑问
我本来想自己控制按钮的颜色,比如点击按钮,按钮背景色改变成想要的颜色,但是没找到。。。。
边栏推荐
- Hit the interview!The latest interview booklet of Ali Jin, nine silver and ten is stable!
- matlab串口读写
- 抗积分饱和PID控制器
- 博云入选 Gartner 中国 DevOps 代表厂商
- Programmer Qixi Gift - How to quickly build an exclusive chat room for your girlfriend in 30 minutes
- Linux-Docker-Mysql安装
- Yolov5 测试和训练自己的数据集
- 划重点!2022面试必刷461道大厂架构面试真题汇总+面经+简历模板
- 如何让 WPF 程序更好地适配 UI 自动化
- 独立站卖家如何使用 WhatsApp Business API 建立有意义的客户关系?
猜你喜欢
随机推荐
动规(18)-并查集基础题——团伙
Flutter使用 json_serializable 解析 JSON 最佳方案
“蔚来杯“2022牛客暑期多校训练营2 G、J、K
电源测试之输出动态响应(Output Dynamic Response Test)
七夕还没选好礼物,快送这套美妆秘籍,保准没错~~
企业应当实施的5个云安全管理策略
Tarjan 求有向图的强连通分量
"Lonely Walking on the Moon" is a powerful medicine, it can't cure the internal friction of happy twist
Hit the interview!The latest interview booklet of Ali Jin, nine silver and ten is stable!
num_workers
The head module of the yolo series
DC/DC电感底部要不要覆铜?
C#控制台退出前操作
Chinese valentine's day of young people crazy to make money, earn 140000 a week
Oracle 19c 单实例 19.3.0 升级到19.11.0 详细教程
两年独立开发经验程序员告诉我们赚钱的经验(听听真正赚到钱的高手做法)
Do you understand the various configurations in the project?
What is DevOps?Enough to read this one!
UMA & Hong Kong Polytechnic & Ali propose SP-ViT to learn 2D space prior knowledge for visual Transformer!
分布式链路追踪Jaeger + 微服务Pig在Rainbond上的实践分享