需要导入什么或如何在活动以外的地方调用 Layout inflater?
public static void method(Context context){
//this doesn't work the getLayoutInflater method could not be found
LayoutInflater inflater = getLayoutInflater();
// this also doesn't work
LayoutInflater inflater = context.getLayoutInflater();
}
我getLayoutInflater
只能在活动中打电话,这是限制吗?如果我想创建自定义对话框并且我想为它膨胀视图,或者如果我想从服务中显示带有自定义视图的 Toast 消息怎么办,我只有来自服务的上下文我没有任何活动但我想显示自定义消息。
我需要在代码中不在活动类中的地方使用充气机。
我怎样才能做到这一点 ?