手机上使用google 搜索引擎[通俗易懂]

手机上使用google 搜索引擎[通俗易懂] <?xmlversion="1.0"encoding="utf-8"?><manifestxmlns:android="http://schemas.android.com/apk/res/android"package="com.android.antking.search"android:versionCode="1&quot

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.android.antking.search"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".SearchActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <--!这里加上-->
            <intent-filter>
            <action android:name="android.intent.action.WEB_SEARCH"></action>
            </intent-filter>
            <meta-data
              android:name="android.app.searchable"
               android:resource="@xml/searchable"/>
        </activity>

    </application>
    <--!这里加上-->
     <meta-date android:name="android.app.default_searchable"
                android:value=".SearchActivity"/>
</manifest>

 package com.android.antking.search;

 

import android.app.Activity;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class SearchActivity extends Activity {
	//定义私有整形变量
	private final int MENU =1;
	//声明Intent对象
	private Intent intent;
	//定义键盘模式为按键搜索模式
	private final int KeyMode =Activity.DEFAULT_KEYS_SEARCH_LOCAL;
	//使用Android自定义图标
	private final int icon = android.R.drawable.ic_menu_search;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        try{
        	setContentView(R.layout.main);
        	//设置键盘模式,按键盘弹出搜索狂
        	setDefaultKeyMode(KeyMode);
        	//获取intent 
        	intent = getIntent();
        	searchWeb(intent);
        }catch(Exception e){
        	Toast.makeText(SearchActivity.this, "一场错误"+e.toString(),
        			Toast.LENGTH_SHORT).show();
        }
        
    }
    /*searchWeb 根据意图行为为键盘算是否进行Web搜索*/
    private void searchWeb(Intent intent){
    	//获取意图的行为
    	String action = intent.getAction();
    	//若意图的行为是Web搜索,则搜索
    	if(Intent.ACTION_WEB_SEARCH.equals(action)){
    		searchHandle(intent);
    	}
    }
    protected void onNewIntent(Intent intent){
    	setIntent(intent);
    	searchWeb(intent);
    }
    /*searchHandle()获取SearchManager的查询*/
    private void searchHandle(Intent intent){
    	final String query = intent.getStringExtra(SearchManager.QUERY);
    	Toast.makeText(this, query, Toast.LENGTH_SHORT).show();
    }
    public boolean onCreateOptionsMenu(Menu menu){
    	boolean result = super.onCreateOptionsMenu(menu);
    	//添加菜单选项
    	MenuItem menuItem = menu.add(0,MENU,0,"nihao");
    	//设置图标
    	menuItem.setIcon(icon);
    	
		return result;
    	
    }
    public boolean onMenuItemSelected(int featureId,MenuItem item){
		switch(item.getItemId()){
		case MENU:
			onSearchRequested();
			return true;
		default:
			return super.onMenuItemSelected(featureId, item);
		}
		
    	
    	
    }
}

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/195063.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • eclipse的创建java程序步骤

    eclipse的创建java程序步骤众所周知,java是一个比较折腾的语言==当然这个折腾更多在软件上,在你好不容易在一大堆英文中下到jdk以及合适的idea或者eclipse合适版本,然后辛辛苦苦配置好的系统变量以后,打开界面以为新建就好了?那不可能,打开新建的时候你一定是崩溃的下面我们一起来看看如何在eclipse建立一个合适的项目包来开开心心的写helloworld吧!1.打开新建点击”包“输入一个包名这里尽量用规范的命名,这里我们给一个Test2.然后出来个界面你以为就可以开始写我们的helloworld了吗?

    2022年7月9日
    18
  • crontab 定时任务配置

    crontab 定时任务配置2019独角兽企业重金招聘Python工程师标准>>>…

    2025年5月27日
    0
  • 求复数的对数[通俗易懂]

    求复数的对数[通俗易懂]其实除了0以外,复数是都可以求解对数的。用欧拉公式可以简单的得到结果。

    2025年6月27日
    1
  • freemarker文件下,bootstrap 点击按钮,切换按钮上的图标

    freemarker文件下,bootstrap 点击按钮,切换按钮上的图标

    2021年7月15日
    93
  • jquery ajax实例代码_jquery ajax详解

    jquery ajax实例代码_jquery ajax详解Jquery在异步提交方面封装的很好,直接用AJAX非常麻烦,Jquery大大简化了我们的操作,不用考虑浏览器的诧异了。推荐一篇不错的jQueryAjax实例文章,忘记了可以去看看,地址为:http://www.cnblogs.com/yeer/archive/2009/07/23/1529460.html和http://www.w3school.com.cn/jquery/

    2022年8月16日
    3
  • 【Tensorflow2.0】Tensorflow2.x的安装教程

    【Tensorflow2.0】Tensorflow2.x的安装教程anaconda可以使tensorflow的安装变的简单昨天tensorflow开发者大会刚开完,会上发布了关于TensorFlow2.0,TensorFlowLite,TensorFlow.js,SwiftforTensorFlow,TFX等产品生态体系的最新更新和首次发布的内容,2019年任会支持tensorflow1.x,但是我们相信,版本的升级会带来易用性和使用性能的提升…

    2022年6月26日
    23

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号