状态栏是,但导航栏不是。
活性
@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=true
和android:fitsSystemWindows=true
,但也不起作用。我还试过在webview中设置setWebChromeClient
,但也不起作用。
1条答案
按热度按时间ni65a41a1#
方法1
将以下代码添加到java文件中。
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
示例Java文件:
方法2
在
styles.xml
中设置以下主题,确保在java文件中扩展Activity
而不是AppCompatActivity
。输出