gpt4 book ai didi

android - 使用 CoordinatorLayout、Swipe2Refresh 和 WebView 时布局顶部的工具栏

转载 作者:行者123 更新时间:2023-11-30 01:46:21 27 4
gpt4 key购买 nike

我在 web View 顶部显示工具栏时遇到问题,我正在尝试找出解决方法。非常感谢任何和所有反馈。

网页 View .xml

<?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>

content_web.xml

<?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>

关于android - 使用 CoordinatorLayout、Swipe2Refresh 和 WebView 时布局顶部的工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33662972/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com