Implement Transparent Condition Bar For Android.Support.V7.Widget.Toolbar

Posted on

Implement transparent condition bar for

– Follow the steps inwards “Replace ActionBar amongst” to implement a simplest toolbar.

– Edit styles.xml to add together the detail of “android:windowTranslucentStatus”.

<resources>      <!-- Base application theme. -->     <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">         <!-- Customize your subject here. -->         <item name="colorPrimary">@color/colorPrimary</item>         <item name="colorPrimaryDark">@color/colorPrimaryDark</item>         <item name="colorAccent">@color/colorAccent</item>         <item name="android:windowTranslucentStatus">true</item>     </style>  </resources>  

Edit to fix the padding (with the superlative of condition bar) of the status.

package com.blogspot.android_er.androidtoolbarex2;  import android.content.res.Resources; import android.os.Bundle; import; import; import android.widget.Toast;  populace aeroplane MainActivity extends AppCompatActivity {      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          Toolbar toolbar = (Toolbar)findViewById(;         setSupportActionBar(toolbar);          toolbar.setPadding(0, getStatusBarHeight(), 0, 0);      }      private int getStatusBarHeight() {         int height;          Resources myResources = getResources();         int idStatusBarHeight = myResources.getIdentifier(                 "status_bar_height", "dimen", "android");         if (idStatusBarHeight > 0) {             superlative = getResources().getDimensionPixelSize(idStatusBarHeight);             Toast.makeText(this,                     "Status Bar Height = " + height,                     Toast.LENGTH_LONG).show();         }else{             superlative = 0;             Toast.makeText(this,                     "Resources NOT found",                     Toast.LENGTH_LONG).show();         }          provide height;     } }  

After finished: