Android 如何继承我的自定义主题?
我需要在服务中升级一个对话框,我发现将对话框窗口类型设置为type\u SYSTEM\u ALERT可以正常工作:Android 如何继承我的自定义主题?,android,dialog,styles,themes,Android,Dialog,Styles,Themes,我需要在服务中升级一个对话框,我发现将对话框窗口类型设置为type\u SYSTEM\u ALERT可以正常工作: dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); 但另一个问题出现了,我在对话框中设置了自定义视图,自定义视图中的组件无法继承我的主题样式,它们使用系统默认的主题样式 更新:这是我的示例代码: public class AlertDialogService extends Servi
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
但另一个问题出现了,我在对话框中设置了自定义视图,自定义视图中的组件无法继承我的主题样式,它们使用系统默认的主题样式
更新:这是我的示例代码:
public class AlertDialogService extends Service {
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
LayoutInflater factory = LayoutInflater.from(this);
final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null);
Dialog alertDialog = new AlertDialog.Builder(this, R.style.Theme_My_Dialog_Alert)
.setTitle(R.string.alert_dialog_text_entry)
.setView(textEntryView)
.create();
alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
alertDialog.show();
}
}
为什么要使用TYPE\u SYSTEM\u ALERT?@pskink如果我不使用TYPE\u SYSTEM\u ALERT,我在服务中显示的对话框将出现错误。这是一个修复错误的解决方法。因此,请不要使用WindowManager,startActivityinstead@pskink我想在服务中显示对话框,而服务是在后台运行的,我不能使用活动的contextWrapper,因为活动可能会在某个时间从您的服务中销毁活动