android how to hide the status bar without hiding the title bar

后端 未结 3 1449
孤街浪徒
孤街浪徒 2021-01-03 13:30

In my application i am working with canvas. I am drawing on canvas. I put canvas color as white. When my app open the canvas is visible along with above status bar. But i w

相关标签:
3条回答
  • 2021-01-03 13:52

    You can't use Window.FEATURE_CUSTOM_TITLE after setting Theme.NoTitleBar. It's enough to use just this theme. Do not set all these flags in code.

    EDIT: Seems I misunderstood your question. I read it again carefully and now I see you're asking about Android 2.x and its notification bar. Your onCreate() method should look like this:

    public void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    
        setContentView(R.layout.name);
    
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
    

    You mustn't set Theme.NoTitleBar or Theme.NoTitleBar.Fullscreen for this activity. Just use the default Theme or don't specify any theme at all.

    0 讨论(0)
  • 2021-01-03 13:58

    It's enough to remove the line

     requestWindowFeature(Window.FEATURE_NO_TITLE);
    

    But if you want to display full screen (without action bar) write too

     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
    
    
      setContentView(R.layout.activity_location_eb);
    
    0 讨论(0)
  • 2021-01-03 14:06

    Am going to tell you how to tackle the title bar and the system notification panel individually and perfectly. Use one or both as per Your Need.

    1.Do not apply any theme to the Activity through XML.

    2.Now, go the corr. Java file and add these lines inside onCreate().. after super.onCreate()..

    Part.a. to remove just Title Bar

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    

    Part.b. to remove the System notification panel

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

    Do not forget to follow them with the usual

    setContentView(R.layout.activity_layout_name);
    
    0 讨论(0)
提交回复
热议问题