[英]Toolbar on top of layout when using CoordinatorLayout, Swipe2Refresh and WebView
我在 webview 上顯示的工具欄有問題,我想弄清楚如何解決這個問題。 非常感謝任何和所有反饋。
<?xml version="1.0" encoding="utf-8"?>
<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" android:fitsSystemWindows="true"
tools:context="com.example.ui.activities.WebActivity">
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_web" />
</android.support.design.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/swipe_refresh">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webview" />
</android.support.v4.widget.SwipeRefreshLayout>
這里有一些關於我如何設置 webview 的代碼。
public class WebActivity extends BaseActivity {
@Bind(R.id.webview)
WebView webView;
@Bind(R.id.toolbar)
Toolbar toolbar;
@Bind(R.id.swipe_refresh)
public SwipeRefreshLayout swipeRefreshLayout;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web);
setSupportActionBar(toolbar);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
webView.reload();
}
});
if (savedInstanceState == null) {
webViewUrl = AUTH_URL;
runOnUiThread(new Runnable() {
@Override
public void run() {
webView = initWebView();
webView.loadUrl(webViewUrl);
}
});
} else {
webViewUrl = savedInstanceState.getString(KEY_URL,AUTH_URL);
runOnUiThread(new Runnable() {
@Override
public void run() {
webView.loadUrl(webViewUrl);
}
});
}
}
}
任何和所有幫助將不勝感激。
CoordinatorLayout
布局需要定義layout_behavior
。 將您的內容更改為:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/swipe_refresh"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webview" />
</android.support.v4.widget.SwipeRefreshLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.