簡體   English   中英

從另一個APK獲取小部件的資源(例如主題APK)

[英]access resources from another apk for widget (like theme apk)

我用可繪制對象和字符串創建了主題,可以通過以下命令訪問主題的資源

String packagename="com.....";
Resources res = context.getPackageManager().getResourcesForApplication(packagename);
int strid = res.getIdentifier(packagename+":string/"+name, "string", packagename);
int drawableid = res.getIdentifier(packagename+":drawable/"+name, "drawable", packagename);

String name = res.getString(resid);
Bitmap bmp = BitmapFactory.decodeResource(res, resid);
//or
Drawable dr=res.getDrawable(resid);

我可以獲取可繪制對象,但是我不知道如何將xml中的可繪制對象設置為小部件。 我只能設置setImageViewResource(int viewid, int resId);

因此,我想問如何從另一個apk訪問xml資源並從中設置小部件可繪制對象。

我想從另一個主題apk訪問這樣的資源,但是我只能訪問drawable(因此不能將其用於小部件)

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
        android:drawable="@drawable/wplayh" />
    <item android:drawable="@drawable/wplay" />
</selector>

您需要一個ContentProvider才能與其他應用共享您的應用數據

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM