我正在尝试在我的工具栏中添加SearchView,我添加了图标,但是当我按下它时,它不会扩展.
这是代码:
main_menu.xml
<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="com.app.try.MainActivity">
<item
android:id="@+id/search"
android:title="@string/search"
android:icon="@drawable/abc_ic_search_api_mtrl_alpha"
app:showAsAction="always"
android:actionViewClass="android.support.v7.widget.SearchView"/>
</menu>
Run Code Online (Sandbox Code Playgroud)
MainActivity.java
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater=getMenuInflater();
inflater.inflate(R.menu.menu_main,menu);
MenuItem searchItem = menu.findItem(R.id.search);
SearchManager searchManager= (SearchManager)getSystemService(Context.SEARCH_SERVICE);
SearchView searchView=null;
if (searchItem!=null) {
Log.d("createOptionMenu","search item not null");
searchView = (SearchView) searchItem.getActionView();
}
if (searchView!=null) {
Log.d("createOptionMenu","search view not null");
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
}else{
Log.e("createOptionMenu","search view null");
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
(这总是显示日志消息"search view null")
AndroidManifest.xml中
...
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
<activity
android:name=".SearchResultActivity" …Run Code Online (Sandbox Code Playgroud) 我只是想在离开页面之前显示一条消息,但我的代码不起作用:
window.onload=function(){
alert("Page with a digital clock");
setInterval(clock,1000);
}
window.onbeforeunload=function(){
alert("Are you sure to leave this page?");
}
Run Code Online (Sandbox Code Playgroud)
"onload alert"工作正常,但第二个不工作..
我有一个应用程序,它有一个加载一些 html 和 js 本地文件的 webview,我想调试 webview。
我已WebView.setWebContentsDebuggingEnabled(true)在 webview 活动中设置了,但该应用程序未显示在chrome://inspect/页面中。
是不是因为都是本地文件?具有 webview 的其他应用程序确实出现在 chrome 检查器中。
我正在尝试按下启用或禁用自动同步的按钮,我知道有一种方法可以启用所有帐户的自动同步ContentResolver.setMasterSyncAutomatically(boolean),但我找不到检查是否启用了"主同步"的方法.有什么方法可以找到它吗?
我要做的是不允许在表单中的文本输入中引入数字字符,但我要用javascript来做.这是我的HTML代码:
<form id="formu">
<input type="text" id="num" />
</form>
Run Code Online (Sandbox Code Playgroud)
这是我的JS代码:
function numero(theEvent){
var evento=theEvent||window.event;
switch(evento.type){
case 'keypress':
if(document.getElementById("num").evento.keyCode>=48&&document.getElementById("num").evento.keyCode<=57){
return false;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我只是想计算增值税,但是当我除以100以获得总价格(价格*增值税/ 100),但它返回0.0.这是我的代码:
a.price=sc.nextInt();
a.vat=sc.nextInt();
a.total=a.precio*a.iva/100;
Run Code Online (Sandbox Code Playgroud)
'total'定义为FLOAT而不是INT