Fredlo2010 Fredlo2010 - 4 months ago 44
Android Question

Android Translucent Status Bar Issues

I want to display an website on and iphone but I want the status bar to show transparent on top of the website. Right it displays a bark/black color.

I have read and tried a hundred of solutions online and read as much documentation about it as possible. Android Status Bar But still I cannot get it to work.

styles.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>

<item name="android:windowTranslucentNavigation">false</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>

<item name="windowActionModeOverlay">true</item>
</style>

</resources>


MainActivity.java

public class MainActivity extends AppCompatActivity {

private WebView myWebview;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

myWebview = (WebView) findViewById(R.id.activity_main_webview);
WebSettings settings = myWebview.getSettings();
settings.setJavaScriptEnabled(true);
myWebview.loadUrl("http://www.google.com");
myWebview.setWebViewClient(new WebViewClient());

}


}

Any idea what could I be doing wrong ?

Answer

Try to change "android:windowTranslucentNavigation" to true. And also set FLAG_LAYOUT_NO_LIMITS in your activity:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window w = getWindow();
            w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        }
Comments