如何在Android版4.0的Android Tab S2上为我的应用程序隐藏android状态栏?

时间:2012-11-06 08:38:10

标签: android statusbar

任何人都可以告诉我任何方式完全隐藏状态栏,仅适用于我在所有活动中的应用。我的应用程序只在Android 4.0 4.0 Android平板电脑上运行。我实际上想删除状态栏上的后面,主页和所有其他点击监听器,或者只是完全隐藏它。这背后的要求是,如果我的应用程序在选项卡上启动,它将保持打开状态,直到用户关闭设备设备并且不应该有任何退出点。我将感激你的谦虚回应。我添加了android:theme =“@ android:style / Theme.Black.NoTitleBar.Fullscreen”manifest.xml.Still无法禁用状态栏。我的活动课程如下:

package com.plugin.myapp;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.CordovaWebViewClient;
import org.apache.cordova.DroidGap;
import org.apache.cordova.CordovaChromeClient;

import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;

public class MainActivity extends DroidGap  {
     private static MainActivity instance;

    // private WebView mWebView;
    @Override
    public void onCreate(Bundle savedInstanceState) {            
        super.onCreate(savedInstanceState);   
        super.init(); 

        //getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
        getWindow().getDecorView().setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
        super.loadUrl("file:///android_asset/www/tdc_tutorial.html");

    }
 // handler for the background updating
    Handler progressHandler = new Handler() 
    {
        public void handleMessage(Message msg) 
        {
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
    };
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        // TODO Auto-generated method stub
        super.onConfigurationChanged(newConfig);

        System.out.println("onConfigurationChanged");
    }
  @Override
    public void init() {
    super.init((CordovaWebView) new WebView(this), new GWTCordovaWebViewClient(this), new CordovaChromeClient(this));
    }

   @Override
    public void onBackPressed() {
        // TODO Auto-generated method stub
        //super.onBackPressed();
    } 

   /* (non-Javadoc)
     * @see org.apache.cordova.DroidGap#onConfigurationChanged(android.content.res.Configuration)
     */

}

我的manifest.xml在下面给出

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.plugin.myapp"
    android:versionCode="1"
    android:versionName="1.0" >

     <uses-sdk
        android:minSdkVersion="15"
        android:targetSdkVersion="15" />

    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.BROADCAST_STICKY" />
    <uses-permission android:name="android.permission.INTERNET" />
<supports-screens     
      android:largeScreens="true"    
      android:normalScreens="true"    
      android:smallScreens="true"  
      android:xlargeScreens="true"  
      android:resizeable="true"    
      android:anyDensity="true"

      /> 

    <application
        android:icon="@drawable/ic_launcher"
        android:label="Android Test"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" > 


        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main"            
            android:screenOrientation="sensorLandscape"
            android:configChanges="orientation">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest> 

3 个答案:

答案 0 :(得分:0)

看看GMD HideBar for ICS。 我在4.0.3平板电脑上使用它,效果非常好!如果您使用dex2jar从apk文件获取jar,我可以在您的构建路径中导入jar文件并使用函数SystemUI.hidebar隐藏或SystemUI.showbar显示:)

答案 1 :(得分:0)

对于没有硬件密钥的设备,除非您使用“Root”设备,否则无法完全隐藏该栏。但是,您可以使用setSystemUIVisiblity将其置于“低调”模式。

答案 2 :(得分:0)

默认情况下,您不应该删除状态栏,因为它是来自Android UI的服务。然后谷歌让你隐藏它,但是如果用户刷了它,它会回来。

但是,如果您在设备上拥有超级用户权限,则可以可以

此代码可以通过杀死它的进程并再次调用它来隐藏和显示StatusBar。

package com.example.statusbar;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

public class MainActivity extends Activity {

    String commandToExecute;

    @Override
    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.activity_main);

        commandToExecute = "/system/xbin/su";
        executeShellCommand(commandToExecute);

        Button btHideStatusBar = (Button) findViewById(R.id.buttonHide);
        Button btShowStatusBar = (Button) findViewById(R.id.buttonShow);


        btHideStatusBar.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                commandToExecute = "/system/xbin/su -c /system/bin/service call activity 42 s16 com.android.systemui";
                executeShellCommand(commandToExecute);

            }
        });

    btShowStatusBar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {

            commandToExecute = "/system/xbin/su -c /system/bin/am startservice -n com.android.systemui/.SystemUIService";
            executeShellCommand(commandToExecute);

        }
    });

    }

    private boolean executeShellCommand(String command) {
        try {

            Runtime.getRuntime().exec(command);

            return true;
        } catch (Exception e) {
            return false;

        }
    }


}