我们将向客户提供设备,他们需要能够通过按钮调用我们。在我的全屏 Activity
中,我有一个调用帮助台电话号码的按钮,因此 onClick()
它执行以下操作:
try {
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
intent.setData(Uri.parse("tel:" + phoneNumber));
mContext.startActivity(intent);
} catch (Exception e) {
Toast.makeText(mContext, mContext.getString(R.string.couldntcall), Toast.LENGTH_LONG).show();
}
当拨号器关闭时,标题栏突然保持可见,我猜它与重写 HOME
按钮有关:
@Override
public void onAttachedToWindow()
{ //HOMEBUTTON
if(OnLockMode())
{
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
else
{
this.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION);
super.onAttachedToWindow();
}
}
有人能解决这个问题吗?
我尝试了以下方法:
我把 list 放在:
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
并在 OnCreate
中使用:
requestWindowFeature(Window.FEATURE_NO_TITLE);
在 onCreate()
和 onResume()
中:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
仍然显示标题栏。
最佳答案
将其添加到 list 中。
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>
在 onCreate() 中
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_home);
View v = findViewById(R.id.home_view);
v.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
其中 home_view 是 xml 文件的父 View 。
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return false;
}
public void onWindowFocusChanged(boolean hasFocus)
{
try
{
if(!hasFocus)
{
Object service = getSystemService("statusbar");
Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
Method collapse = statusbarManager.getMethod("collapse");
collapse .setAccessible(true);
collapse .invoke(service);
}
}
catch(Exception ex)
{
}
}
您无法捕获 home 事件,您唯一能做的就是给您的应用程序 home 类别并让用户选择。
<category android:name="android.intent.category.HOME" />
关于android - TYPE_KEYGUARD 调用电话后保持全屏模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10073898/