[英]Android Toolbar in webapp
I am developing a web app, and here I have a problem. 我正在开发一个Web应用程序,在这里我遇到了问题。
I have a tool bar(android widget toolbar) with logo and search button 我有一个带有徽标和搜索按钮的工具栏(android小部件工具栏)
As you can see I have the login page(webview). 如您所见,我有登录页面(webview)。 I want to user to see this search button after users login to the webpage.
我希望用户在登录网页后看到此搜索按钮。 How should I do that?
我应该怎么做?
Edited: 编辑:
In my toolbar.xml 在我的toolbar.xml中
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/my_toolbar"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#000000"
android:elevation="3dp"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
</android.support.v7.widget.Toolbar>
In my menu_main.xml 在我的menu_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<menu 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"
tools:context=".MainActivity">
<item
android:id="@+id/action_search"
android:orderInCategory="200"
android:title="@string/action_search"
android:icon="@drawable/ic_action_search"
app:showAsAction="ifRoom|collapseActionView"
app:actionViewClass="android.support.v7.widget.SearchView"/>
</menu>
And in MainActivity.java onCreate, 在MainActivity.java onCreate中,
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
//toolbar.setNavigationIcon(R.mipmap.logo9);
toolbar.setTitle("");
toolbar.setSubtitle("");
...... ......
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
return super.onCreateOptionsMenu(menu);
}
And finally in activity_main.xml, I just include the toolbar, 最后,在activity_main.xml中,我仅包含工具栏,
<include
android:id="@+id/tool_bar"
layout="@layout/tool_bar"
></include>
If the search button is an Android View
, you can hide it by calling View.setVisibility(View.GONE)
. 如果搜索按钮是Android
View
,则可以通过调用View.setVisibility(View.GONE)
将其隐藏。
If you have instead defined it as a menu
XML resource and loaded it in this Activity
, then just don't load the menu
resource unless the user is logged in. That is done in public boolean onCreateOptionsMenu(Menu menu)
of the Activity
. 如果您已将其定义为
menu
XML资源并在此Activity
加载了它,那么除非用户登录,否则不要加载menu
资源。这是通过Activity
public boolean onCreateOptionsMenu(Menu menu)
来完成的。
If you go to another Activity
after logging in, then just use a separate Toolbar
there, with the icon like here, but without one in the login Activity
. 如果您在登录后转到另一个
Activity
,则只需在此处使用单独的Toolbar
,其图标如下所示,但登录Activity
没有一个。
Please provide more information on how you added the search icon to the Toolbar
in the first place, then I will be able to help you more. 请首先提供有关如何将搜索图标添加到
Toolbar
更多信息,然后我们将为您提供更多帮助。
Edit: 编辑:
You can use the WebView.getUrl()
method to get the URL of the displayed website, if your login page is on login.php
, you can look if the URL is that, and then not show the search icon. 您可以使用
WebView.getUrl()
方法获取显示的网站的URL,如果您的登录页面位于login.php
,则可以查看该URL是否,然后不显示搜索图标。 For example you can check the URL with String.contains()
, like: .contains("login.php")
. 例如,您可以使用
String.contains()
检查URL,例如: .contains("login.php")
。 And if that is true don't show the button. 如果是这样,请不要显示该按钮。
在此活动的样式中,为此活动在您的样式中使用此属性
<item name="android:windowNoTitle">true</item>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.