导航栏不会半透明

时间:2018-04-06 14:08:36

标签: android navigationbar

状态栏是,但导航栏不是。

活性

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pictures);

    getSupportActionBar().hide();

    swipeLayout = findViewById(R.id.swipe_container);

    final WebView myWebView = findViewById(R.id.webview);
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setDisplayZoomControls(false);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setUseWideViewPort(true);
    myWebView.addJavascriptInterface(new WebAppInterface(this), "Android");
    myWebView.setWebChromeClient(new WebChromeClient());
    myWebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url)
        {
            if (swipeLayout.isRefreshing()) {
                swipeLayout.setRefreshing(false);
            }
            super.onPageFinished(view, url);
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            myWebView.loadUrl("file:///android_asset/errorPage.html");
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Log.i("mooverApp", "Host: "+url);
            if (Uri.parse(url).toString().contains("eupdates")) {
                // This is my web site, so do not override; let my WebView load the page
                return false;
            }
            // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(intent);
            return true;
        }
    });
    myWebView.setBackgroundColor(getResources().getColor(R.color.colorBlack));
    myWebView.loadUrl(URL_FIRST_PART + URL_SECOND_PART + "main.php?targ=postImages" +  QuickstartPreferences.lastItemForQueryString);
    swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            myWebView.loadUrl(URL_FIRST_PART + URL_SECOND_PART + "main.php?targ=postImages" +  QuickstartPreferences.lastItemForQueryString);
        }
    });
    swipeLayout.setColorSchemeResources(
            R.color.colorPrimary,
            R.color.colorPrimary);

}

主要布局

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.eupdates.eupdates.PicturesActivity"
    >

    <include
        layout="@layout/content_pictures"
        />

</android.support.design.widget.CoordinatorLayout>

内容布局

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.eupdates.eupdates.PicturesActivity"
    tools:showIn="@layout/activity_pictures"
    >

    <android.support.v4.widget.SwipeRefreshLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/swipe_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >

        <WebView  xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/webview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorBlack"
            />

    </android.support.v4.widget.SwipeRefreshLayout>

</android.support.constraint.ConstraintLayout>

V21 /样式

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>
<style name="Theme.AppCompat.Translucent">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
    <item name="android:fitsSystemWindows">false</item>
</style>

基本上导航栏不会半透明。我尝试在样式中设置android:fitsSystemWindows true,两个栏都不是半透明的。 我还尝试在根布局中设置android:fitsSystemWindows=trueandroid:fitsSystemWindows=true,但它也不起作用。 我也在webview中尝试了顶级集setWebChromeClient,但也没有用。

1 个答案:

答案 0 :(得分:0)

方法1

在java文件中添加以下代码。 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } }

示例Java文件:

styles.xml

方法2

Activity中设置以下主题。确保在您的java文件中扩展AppCompatActivity而不是<style name="TranslucentStatusBar" parent="@android:style/Theme.Holo.Light.NoActionBar"> <item name="windowActionBar">false</item> <item name="windowNoTitle">true</item> <item name="android:windowTranslucentNavigation">true</item> <item name="android:windowTranslucentStatus">true</item> </style>

with open('the_file.txt') as f:
    s = f.read()
s = s[:64] + s[64:90].lower() + s[90:]
with open('the_file.txt', 'w') as f:
    f.write(s)

<强>输出

enter image description here