program story

Android에서 상태 표시 줄을 숨기는 방법

inputbox 2020. 8. 26. 07:50
반응형

Android에서 상태 표시 줄을 숨기는 방법


링크를 참조했습니다 . 사용자가 EditText (예 : To :)를 클릭하면 키보드가 튀어 나와 동시에 스크롤하여 나머지 모든 뷰 (예 : 작성, 제목, 보내기 버튼)를 볼 수 있습니다. 그 화면. 마찬가지로 내 앱에는 위젯이나 뷰가 있다는 점에서 하나의 활동이 있습니다. 사용자가 내 활동에있는 Edittext를 클릭하면 키보드가 튀어 나오고 스크롤하여 나머지보기를 볼 수 있다고 가정합니다. 그러나 android:theme="@android:style/Theme.NoTitleBar.Fullscreen"매니페스트 에이 속성 제공하면 나머지 뷰를 볼 수 있도록 스크롤 할 수 없지만 속성을 제공하면android:theme="@android:style/Theme.NoTitleBar"매니페스트에서 이와 같이 스크롤하여 나머지보기를 볼 수 있지만 해당 화면에는 상태 표시 줄이 있습니다. 여기에서는 전체 화면을 원하며 키보드가 튀어 나와도 스크롤하여 나머지보기를 볼 수 있습니다 ..? 이것을 위해 내가 어떤 변화를 ..?


활동에 이것을 작성하십시오.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

여기에서 문서 확인 : https://developer.android.com/training/system-ui/status.html

앱이 전체 화면으로 전환됩니다. 상태 표시 줄도없고 제목 표시 줄도 없습니다. :)


 if (Build.VERSION.SDK_INT < 16) {
   getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
 } else {
     View decorView = getWindow().getDecorView();
      int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
      decorView.setSystemUiVisibility(uiOptions);
      ActionBar actionBar = getActionBar();
      actionBar.hide();
 }

사용 테마 "Theme.NoTitleBar.Fullscreen"와 설정 시도 "android:windowSoftInputMode=adjustResize"의 활동을 위해 AndroidManifest.xml.당신은 세부 사항을 찾을 수 있습니다 여기에 .


하나의 활동에서 이것이 필요한 경우 setContentView 전에 onCreate를 입력해야합니다.

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.your_screen);

이것을 Activity 클래스에 추가하십시오.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(
                        WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);
    // some your code
}

당신이 사용 Activity.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

void hideStatusBar() {
        if (Build.VERSION.SDK_INT < 16) {
           getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        } else {
            View decorView = getWindow().getDecorView();
            int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
            decorView.setSystemUiVisibility(uiOptions);
        }
    }

You can use this method to hide the status bar. And this is important to hide the action bar too. In this case, you can getSupportActionBar().hide() if you have extended the activity from support lib like Appcompat or you can simply call getActionBar().hide() after the method mentioned above. Thanks


Change the theme of application in the manifest.xml file.

android:theme="@android:style/Theme.Translucent.NoTitleBar"

Use this code:

requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.youractivityxmlname);

This code hides status bar.

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

to hide action bar write this line:-

requestWindowFeature(Window.FEATURE_NO_TITLE);

both lines can be written collectively to hide Action bar and status bar. all these lines must be written before setContentView method call in onCreate method.


Use this code for hiding the status bar in your app and easy to use

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

You can hide by using styles.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>
<style name="HiddenTitleTheme" parent="AppTheme">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
</style>

just call this in your manifest like this android:theme="@style/HiddenTitleTheme"


In AndroidManifest.xml -> inside the activity which you want to use, add the following:

android:theme="@style/Theme.AppCompat.Light.NoActionBar"
//this is for hiding action bar

and in MainActivity.java -> inside onCreate() method, add the following :

this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//this is for hiding status bar

This is the official documentation about hiding the Status Bar on Android 4.0 and lower and on Android 4.1 and higher

Please, take a look at it:

https://developer.android.com/training/system-ui/status.html


You can hide status bar by setting it's color to transperant using xml. Add statusBarColor item to your activity theme:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

We cannot prevent the status appearing in full screen mode in (4.4+) kitkat or above devices, so try a hack to block the status bar from expanding.

Solution is pretty big, so here's the link of SO:

StackOverflow : Hide status bar in android 4.4+ or kitkat with Fullscreen


This solution work for me :)

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= 19) {
           getWindow().setFlags(AccessibilityNodeInfoCompat.ACTION_NEXT_HTML_ELEMENT, AccessibilityNodeInfoCompat.ACTION_NEXT_HTML_ELEMENT);
           getWindow().getDecorView().setSystemUiVisibility(3328);
    }else{
           requestWindowFeature(Window.FEATURE_NO_TITLE);
           this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    DataBindingUtil.setContentView(this, R.layout.activity_hse_video_details);

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // If the Android version is lower than Jellybean, use this call to hide
    // the status bar.
    if (Build.VERSION.SDK_INT < 16) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    } else {
       View decorView = getWindow().getDecorView();
       // Hide the status bar.
       int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
       decorView.setSystemUiVisibility(uiOptions);
       // Remember that you should never show the action bar if the
       // status bar is hidden, so hide that too if necessary.
       ActionBar actionBar = getActionBar();
       actionBar.hide();
    }

    setContentView(R.layout.activity_main);

}
...
}

Used in Manifest

android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen"

Under res -> values ->styles.xml

Inside the style body tag paste

<item name="android:windowTranslucentStatus" tools:targetApi="kitkat">true</item>

requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

참고URL : https://stackoverflow.com/questions/5431365/how-to-hide-status-bar-in-android

반응형