安卓:我怎样才能在状态栏电池图标资源ID或完整的文件路径/名? [英] Android: How can I get Battery Icon Resource ID or full file path/name in Status Bar?

查看:217
本文介绍了安卓:我怎样才能在状态栏电池图标资源ID或完整的文件路径/名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要检查电池图标和水平,状态栏是否正确改变了,所以我希望得到的电池图标资源ID或在状态栏上的完整的文件路径/名称。

我试图用电池管理器,以获得图标的资源ID:

  intent.getIntExtra(BatteryManager.EXTRA_ICON_SMALL,0)

不过,我遇到了同样的问题,因为笔者所做的:
安卓访问"系统" -drawables

我得到同样的图标,其路径是 /res/drawable/stat_sys_battery.xml ,无论级别是什么。我渴望知道的这是为什么图标不与状态栏的图标相同?我的目标是让状态栏的图标。

我已经寻找答案相当长的一段时间,但关于这一主题的大部分信息涉及到改变状态栏电池图标,而我的问题是如何让状态栏的地位和图标,即我不想修改图标。

请帮帮我!先谢谢了。


解决方案

  

我急切地想知道为什么这个图标是不是与状态栏的图标相同。


有一样的状态栏图标,因为是状态栏图标即可。电池电量是 LevelListDrawable 在该资源实现的。

除非你正在构建自己的自定义固件,你没有进入实际 LevelListDrawable 的对象,因此,你不能检查它。

I want to examine whether the battery icon and level in status bar are changed correctly, so I want to get the Battery Icon Resource ID or the full file path/name in Status Bar.

I tried to use the Battery Manager to get the icon's resource ID:

intent.getIntExtra(BatteryManager.EXTRA_ICON_SMALL, 0)

However, I encountered the same problem as the author did: Android: access "system"-drawables

I get the same icon, whose path is /res/drawable/stat_sys_battery.xml, no matter what the level is. I am eager to know why is this icon not the same with status bar's icon? My goal is to get the status bar's icon.

I have searched for the answer for quite a while, but most posts on this topic pertain to changing the battery icon in status bar, whereas my question is on how to get the status bar's status and icon, i.e. I do not want to modify the icon.

Please help me! Thanks in advance.

解决方案

I am eager to know why this icon is not the same with status bar's icon.

It is the same as the status bar's icon, because it is the status bar's icon. The battery level is a LevelListDrawable as implemented in that resource.

Unless you are building your own custom firmware, you do not have access to the actual LevelListDrawable object, and therefore you cannot examine it.

这篇关于安卓:我怎样才能在状态栏电池图标资源ID或完整的文件路径/名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆