当前位置:网站首页>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();
}
}
疑问
我本来想自己控制按钮的颜色,比如点击按钮,按钮背景色改变成想要的颜色,但是没找到。。。。
边栏推荐
猜你喜欢
随机推荐
Nacos手摸手教学【二】Nacos注册中心
Flutter 使用 json_serializable 解析 JSON 支持泛型
正则表达式
七夕疯狂搞钱的年轻人,一周赚14万
COMSOL空气反应 模型框架
The head module of the yolo series
244页pdf!《2022 中国云计算生态蓝皮书》发布
一分钟认识 IndexedDB 数据库,太强大了!
Do you understand the various configurations in the project?
动规(18)-并查集基础题——团伙
企业应当实施的5个云安全管理策略
划重点!2022面试必刷461道大厂架构面试真题汇总+面经+简历模板
Chinese valentine's day of young people crazy to make money, earn 140000 a week
电源输出的Overshoot和Undershoot 测试
Geoffrey Hinton:深度学习的下一个大事件
程序猿七夕礼物-如何30分钟给女友快速搭建专属语聊房
TensorFlow学习记录(三):高阶操作 & 神经网络与全连接层
C#控制台退出前操作
云原生Devops 的实现方法
直击面试!阿里金九银十最新面试小册 稳过!