问题描述
目前,我正在写的框架Xposed一个模块,但现在我有一个问题。我想从我自己的包膨胀的布局。我想我可以做到这一点通过使用此code:
At the moment I'm writing a module for the Xposed framework but now I have a problem. I want to inflate a layout from my own package. I thought I can do this by using this code:
Context context = (Context) XposedHelpers.getObjectField(object, "mContext");
LayoutInflater inflater = LayoutInflater.from(context);
View buttons = inflater.inflate(R.layout.volumebuttons, null, false);
但是,这并不正常工作。当涉及到第三行抛出一个异常(抱歉目前还不清楚这个提法,我不知道真的是什么一种异常被抛出 - 我不能与Xposed框架看出来)。你有什么想法,为什么我不能用这个code夸大我的布局?
But this does not work. When it comes to the third line an exception is thrown (sorry for this unclear formulation. I do not realy know what a kind of exception is thrown - I can't see it with the Xposed framework). Do you have any ideas why I can't use this code to inflate my layout?
推荐答案
我的资金中拿出它的工作原理。我真的必须创建为我的应用上下文对象。每个人是如何寻找,这里是code,使用它可以做到这一点:
I fund out it works. I realy had to create a context object for my application. For everyone how is looking for that here is the code with which you can do this:
Context context = (Context) XposedHelpers.getObjectField(object, "mContext");
context = context.createPackageContext(packageName, Context.CONTEXT_IGNORE_SECURITY);
这篇关于充气布局Xposed模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!