简体   繁体   English

如何仅针对Android Tabs2和Android version4.0.3上的应用程序隐藏android状态栏?

[英]How to hide android status bar just for my application on Android Tabs2 fro Android version4.0.3?

Can any one please tell me any way to hide status bar completely just for my application on all activities. 谁能告诉我任何一种完全隐藏状态栏的方法,仅针对我在所有活动中的应用程序。 My application only runs on android tabs with 4.0.3 Android. 我的应用程序仅在带有4.0.3 Android的android标签上运行。 I actually want to remove the back, home and all the other click listeners on the status bar or just completely hide it. 我实际上是想删除状态栏上的背面,房屋和所有其他单击侦听器,或者只是完全隐藏它。 The requirement behind this is that if once my application starts on a tab it stays on until user switches off the device device and there should not be any exit point. 这背后的要求是,一旦我的应用程序在选项卡上启动,它就会一直保持打开状态,直到用户关闭设备设备,并且不应有任何退出点。 I will be grateful for your humble response. 谢谢您的谦卑。 I have added android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" manifest.xml.Still not able to disable the status bar. 我添加了android:theme =“ @ android:style / Theme.Black.NoTitleBar.Fullscreen” manifest.xml。仍然无法禁用状态栏。 My activity class is given below 我的活动课程如下

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)
     */

}

and my manifest.xml is given below 和我的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> 

Take a look at GMD HideBar for ICS . 看一下ICS的GMD HideBar I used it on my 4.0.3 tablet and it works very good! 我在4.0.3平板电脑上使用了它,效果很好! if you use dex2jar to get jar from apk file, I could import jar file in your buildpath and use function SystemUI.hidebar to hide or SystemUI.showbar to show :) 如果你使用dex2jar摆脱apk文件罐子,我可以在你的构建路径中导入jar文件和使用功能SystemUI.hidebar隐藏或SystemUI.showbar展示:)

For devices without hardware key, unless you "Root" device, there's no way to completely hide the bar. 对于没有硬件密钥的设备,除非您“根”设备,否则无法完全隐藏该限制。 You can, however, put it in "low profile" mode using setSystemUIVisiblity . 但是,您可以使用setSystemUIVisiblity将其置于“低配置文件”模式。

By default, you shouldn`t remove the statusbar, because it is a service from the Android UI. 默认情况下,您不应删除状态栏,因为它是Android用户界面中的一项服务。 Then Google let you hide it, however if the user swipes it up, it will come back. 然后,Google让您隐藏它,但是如果用户向上滑动它,它将返回。

But, yes it is possible to do if you have root access on the device. 但是,如果您在设备上具有root用户访问权限, 则可以这样做

This code can hide and show the StatusBar by killing it`s proccess and calling it back again. 此代码可以通过杀死进程并再次调用来隐藏和显示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;

        }
    }


}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM