0

我想知道如何使用 xposed 模块跟踪电池,删除现有的电池表,并动态添加我自己的电池表。我不知道如何开始。我看到了一些源代码,但无法理解它们是如何工作的。请提供一些示例或基本想法以开始使用(链接也将非常有帮助)

以下是我的ROM(CoolUI8)中的布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:gravity="center_vertical" android:id="@id/system_icons" android:layout_width="wrap_content" android:layout_height="fill_parent"
  xmlns:android="http://schemas.android.com/apk/res/android">
    <com.android.keyguard.AlphaOptimizedLinearLayout android:gravity="center_vertical" android:orientation="horizontal" android:id="@id/statusIcons" android:layout_width="wrap_content" android:layout_height="fill_parent" />
    <include android:id="@id/msim_hd_voice_on" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="2.0dip" layout="@layout/hd_voice_on" />
    <include android:id="@id/msim_signal_cluster" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="2.0dip" layout="@layout/signal_cluster_view_yulong" />
    <com.android.systemui.BatteryViewGroup android:id="@id/battery_field" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="4.0dip">
        <TextView android:textAppearance="@style/TextAppearance.StatusBar.Text.Style" android:layout_gravity="center_vertical" android:id="@id/battery_level" android:visibility="gone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="@dimen/battery_level_padding_end" />
        <FrameLayout android:layout_gravity="center_vertical" android:id="@id/battery_group" android:layout_width="wrap_content" android:layout_height="wrap_content">
            <ImageView android:id="@id/battery_frame" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/stat_sys_battery_frame" android:scaleType="center" />
            <com.android.systemui.BatteryMeterView android:id="@id/battery" android:layout_width="25.0dip" android:layout_height="12.0dip" />
            <ImageView android:id="@id/battery_charge" android:visibility="gone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="25.0dip" android:src="@drawable/stat_sys_battery_charge_flag" android:scaleType="center" />
        </FrameLayout>
    </com.android.systemui.BatteryViewGroup>
</LinearLayout>

我已经成功隐藏了现有的电池表(隐藏了整个 FrameLayout,id 为:battery_group),但我想在此处添加自定义电池表...如果您有任何与此主题相关的信息,请回复 :)

4

1 回答 1

0

我在我的 xposed 模块中用黑色替换了 WhatsApp 的蓝色刻度。我觉得你的问题和我的差不多。

我不知道这是否对您有帮助,但它会帮助您开始使用 xposed。

您可以从 IXposedHookInitPackageResources 接口实现此方法

@Override
public void handleInitPackageResources(XC_InitPackageResources.InitPackageResourcesParam initPackageResourcesParam) throws Throwable {
    if (!initPackageResourcesParam.packageName.equals("com.whatsapp"))
        return;

    //create the resource instance for your package
    modRes = XModuleResources.createInstance(MODULE_PATH, initPackageResourcesParam.res);

    //example to change xml attribute like dimension
    initPackageResourcesParam.res.setReplacement("com.whatsapp", "dimen", "tab_height", modRes.fwd(R.dimen.tab_height));

    //example to replace icon -- battery icon in your case
    initPackageResourcesParam.res.setReplacement("com.whatsapp", "drawable", "message_got_read_receipt_from_target", modRes.fwd(R.mipmap.ic_black_tick_conv));
    initPackageResourcesParam.res.setReplacement("com.whatsapp", "drawable", "message_got_read_receipt_from_target_onmedia", modRes.fwd(R.mipmap.ic_black_tick_conv));
    initPackageResourcesParam.res.setReplacement("com.whatsapp", "drawable", "msg_status_client_read", modRes.fwd(R.mipmap.ic_black_tick_main));

}

你可以参考我的 xposed 模块代码来查看一些 xposed 的例子

https://github.com/suraj0208/WhatsappExtensions

最后一件事,如果这有助于您接受它作为答案。左边的勾号图标:D

于 2016-12-13T03:25:21.253 回答