活动不会在全屏幕显示 [英] Activity doesn't show in full screen
问题描述
我定义我的项目新的活动,我有全屏一些麻烦。
I defined a new Activity on my project and I have some trouble with fullScreen.
我在清单文件中是这样定义的:
I defined in the manifest file like this:
<activity android:name=".Test"
android:launchMode="singleInstance" android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
.............
>
如果我开始的活动从其他活动中,我得到了想要的全屏幕。问题是,当我开始这项活动从一个BroadcastReceiver - 我需要打开一个BroadcastReceiver这样的事情在这个活动:
If I start the activity from another activity, I got the desired full screen. The problem is when I start this activity from a BroadcastReceiver - I need to open this activity inside a BroadcastReceiver something like this:
public void onReceive(Context context, Intent intent) {
Intent test = new Intent(context, Test.class);
test.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(test);
}
我想这样过:
I tried like this too:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.test);
}
和无全屏如果该活动从我BroadcastReciever开始。
and no full screen if the activity starts from my BroadcastReciever.
为什么我没有得到充分的屏幕上这个案子?还有就是创建后的活动和可见的任何方式要求全屏?
Why I don't get full screen on this case? There is any way to request full screen after the Activity is created and visible?
推荐答案
我喜欢这个问题。有一种方法,我忽略了问题文本添加 - 我不认为这是相关的。因为我想这个活动来拦截(不反应),home键preSS,基于这个原因,我重写onAttachedToWindow()方法是这样的:
I fond the issue. There is a method I omitted to add in question text - I didn't thought it's relevant. Because I want this activity to intercept (do not react) home button press, and for this reason I override onAttachedToWindow() method like this:
public void onAttachedToWindow() {
getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
和这里是问题。有些时候,因为这个,我的活动并没有得到充分的画面。为了解决这个问题,我不知道这是不是最好的方式,我加了一个延迟到这一code,像这样的:
And here is the issue. Some times, because of this, my activity didn't get full screen. To fix this, I don't know if this is the best way, I added a delay to this code, like this:
public void onAttachedToWindow() {
handler.sendEmptyMessageDelayed(100,100);
super.onAttachedToWindow();
}
和处理程序:
public boolean handleMessage(Message msg) {
getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
}
这解决了我的问题。我希望帮助别人!
and this solved my issue. I hope this help someone!
这篇关于活动不会在全屏幕显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!