如何隐藏特定webview网址的线性布局工具栏?
问题描述:
我有一个在线性布局中创建的工具栏,与相对布局web视图相关联。如何隐藏这个工具栏的特定网址为例如:'index.php' 我的工具栏代码如下给出 我已经尝试了很多次,不能使它与给定的答案正确工作,所以用xml布局代码更新代码。如何隐藏特定webview网址的线性布局工具栏?
XML布局代码,请你帮
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">
<FrameLayout
android:id="@+id/webview_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible"
tools:context=".universalwebview.MainActivity">
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none" />
</FrameLayout>
<LinearLayout
android:id="@+id/toolbar_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#fff"
android:orientation="horizontal">
<ImageView
android:id="@+id/home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:padding="10dp"
android:src="@drawable/ic_action_home"
android:tint="@color/tintcolor" />
<ImageView
android:id="@+id/search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:padding="10dp"
android:src="@drawable/ic_action_search"
android:tint="@color/tintcolor" />
<ImageView
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:padding="10dp"
android:src="@drawable/ic_action_add"
android:tint="@color/tintcolor" />
<ImageView
android:id="@+id/profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:padding="10dp"
android:src="@drawable/ic_action_profile"
android:tint="@color/tintcolor" />
<ImageView
android:id="@+id/settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:padding="10dp"
android:src="@drawable/ic_action_settings"
android:tint="@color/tintcolor" />
</LinearLayout>
<ImageView
android:id="@+id/image_splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:visibility="visible"
android:src="@drawable/splash" />
</RelativeLayout>
答
在你的MainActivity代码无法通过default.As那是地方让你Showtoolbar布尔变量错误在您的底部导航实际上是populating.So它可能会给出运行时错误。而且,当URL包含“index.php”时,可以隐藏线性布局。
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
if(url.contains("index.php")
{
findViewById(R.id.toolbar_footer).setVisibility(View.GONE);
}
else
{
findViewById(R.id.toolbar_footer).setVisibility(View.VISIBLE);
}
}
在您的WebViewClient下调用它。
答
- 此网址
- 使用
url.contains("index.php")
判断 - 设置
showToolBar = false;
或showToolBar = true;
- 使用
if (showToolBar) {} else {}
试试这个。
private boolean showToolBar;
private LinearLayout llToolbarContainer;
public void initWebView() {
llToolbarContainer = (LinearLayout) findViewById(R.id.toolbar_footer);
String url = "your_url";
if (url.contains("index.php")) {
showToolBar = false;
llToolbarContainer.setVisibility(View.GONE);
} else {
showToolBar = true;
llToolbarContainer.setVisibility(View.VISIBLE);
}
mSearch = (ImageView) findViewById(R.id.search);
mAdd = (ImageView) findViewById(R.id.add);
mProfile = (ImageView) findViewById(R.id.profile);
mHome = (ImageView) findViewById(R.id.home);
mSettings = (ImageView) findViewById(R.id.settings);
// ImageView mRefresh = (ImageView) findViewById(R.id.refresh);
mSettings.setOnClickListener(this);
mHome.setOnClickListener(this);
mProfile.setOnClickListener(this);
mSearch.setOnClickListener(this);
mAdd.setOnClickListener(this);
// mRefresh.setOnClickListener(this);
}
答
您需要创建一个函数,该函数将隐藏工具栏。和自定义WebViewClient
创建WebView
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (url.contains("index.php")) {
hideToolBar();
}
}
};
这样的事情。不知道你需要onPageFinished
,但你可以找到更多信息WebViewClient
非常感谢您的帮助..它帮助了很多... –