Android:访问 "system"-drawables

标签 android drawable

我目前正在开发一个显示电池状态的应用程序,我想使用 Android 可绘制对象而不是自己的图像来减小应用程序的大小。

我发现这个页面列出了每个 SDK 版本的可用图像和可用性:
http://www.fixedd.com/projects/android_drawables_display

我的问题:如何访问“系统”-drawables?如果您单击链接并选择“状态”选项卡,则有一些电池可抽取项,如“stat_sys_battery_0”,但我无法访问它,Eclipse 不为其提供智能感知,如果我不编译应用程序使用其中一个可绘制对象。

由于这些可绘制对象是所有 SDK 版本的一部分,我认为我应该能够使用它们,或者这些“特殊”可绘制对象是否以某种方式受到保护,因此它们只能由系统功能使用(而不是应用)?

任何想法都会受到赞赏。

选择0r

最佳答案

希望这就是您要找的:

private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){
    @Override
    public void onReceive(Context arg0, Intent intent) {

        int level = intent.getIntExtra("level", 0);

        int batteryIconId = intent.getIntExtra("icon-small", 0);
        Button toolBarBattery = (Button) findViewById(R.id.toolBarButton);

        LevelListDrawable batteryLevel = (LevelListDrawable) getResources().getDrawable(batteryIconId);
        batteryLevel.setLevel(level);

        toolBarBattery.setBackgroundDrawable(batteryLevel);

    }
};

关于Android:访问 "system"-drawables,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4891598/

相关文章:

android - Recyclerview AddOnScrollListener

android - sub3.0 设备上的 ActionBar - 使用我的自定义系统实现 ActionBarSherlock?

android - 寻找以单一 Activity 应用程序方法在 Android 中实现 SearchView 的想法

Android可绘制: layer-list repeat bitmap does not load when entirely covered

android - 从路径创建 BitmapDrawable

android - android kitkat 版本中的 javax.net.ssl.SSLException : Connection closed by peer.

Android View 相同的宽度和高度

android - 如何检查整数数组中的android资源类型

android - 以编程方式更改 ShapeDrawable 的描边宽度

android - 如何在 android 的 xml 中将我的文本轮廓着色为黑色