如何在Android 3.0(Honeycomb)中以编程方式降低系统栏亮度?
尝试使用以下代码:
View v = findViewById(R.id.myview);
v.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>
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);
where home_view是xml文件的父视图。
@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)
{
}
}
你无法捕获主屏幕事件,唯一的方法是为你的应用程序指定主屏幕类别,并让用户进行选择。
<category android:name="android.intent.category.HOME" />