Transparent action bar and status bar like Uber

后端 未结 6 906
自闭症患者
自闭症患者 2020-12-08 03:29

I\'ve done a few researches on this topic but I couldn\'t found some solution for my App/ Activity.

  1. I have tried to get a transparent action bar.
6条回答
  •  再見小時候
    2020-12-08 04:04

    1. First, you have to change your layout structure to show MAP under transparent Toolbar & StatusBar and also to remove left and right gap from your existing Toolbar.

    activity_main.xml:

    
    
    
        
    
            
    
            
    
                
    
            
        
    
    

    2. In your MainActivity, do below things to initialize Toolbar and make Toolbar and StatusBar as transparent.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    
        // Toolbar :: Transparent
        toolbar.setBackgroundColor(Color.TRANSPARENT);
    
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle("StackOverflow");
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    
        // Status bar :: Transparent
        Window window = this.getWindow();
    
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        {
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.setStatusBarColor(Color.TRANSPARENT);
        }
    
        ...........
        .................. 
    }
    

    3. Apply below theme to your MainActivity.

    values/styles.xml:

    
    
    
    

    AndroidManifest.xml:

    
    
    
    

    OUTPUT:

    FYI, I have just used an sample image of map in my content LinearLayout to show the behavior. For your case put all of your content(searchbar, map) inside it.

    Hope this will help~

提交回复
热议问题