前段时间仿QQ做了一个搜索框样式,个人认为还不错,留在这里给大家做个参考,希望能帮助到有需要的人。

首先上截图(图1:项目中的样式,图2:demo样式):

不多说直接上代码:

Main.axml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000">
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="match_parent"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/search_back">
<ImageView
android:layout_width="23dp"
android:layout_marginTop="2dp"
android:layout_height="23dp"
android:layout_marginLeft="5dp"
android:padding="2dp"
android:layout_marginBottom="2dp"
android:src="@drawable/icon_query" />
<EditText
android:id="@+id/et_search"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="30dp"
android:padding="2dp"
android:background="@null"
android:hint="搜索"
android:layout_gravity="center_vertical"
android:singleLine="true"
android:textSize="17sp"
android:textColor="#000000" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>

MainActivity.cs

using Android.App;
using Android.Widget;
using Android.OS;
using Android.Views;
using Android.Runtime;
using System;
using Android.Views.InputMethods; namespace SearchDemo
{
[Activity(Label = "SearchDemo", MainLauncher = true)]
public class MainActivity : Activity, View.IOnKeyListener
{
EditText et_search; protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main); et_search = (EditText)FindViewById(Resource.Id.et_search);
et_search.ImeOptions = Android.Views.InputMethods.ImeAction.Search; //修改键盘按钮
et_search.SetOnKeyListener(this);
} public bool OnKey(View v, [GeneratedEnum] Keycode keyCode, KeyEvent e)
{
if (keyCode == Keycode.Enter || keyCode == Keycode.Search)
{
InputMethodManager imm = (InputMethodManager)this.GetSystemService(InputMethodService);
if (imm != null)
{
imm.HideSoftInputFromWindow(Window.DecorView.WindowToken, ); //隐藏键盘
}
}
Toast.MakeText(this, et_search.Text, ToastLength.Short).Show();
return false;
}
}
}

search_bcak.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#F5F5F5" />
<corners
android:topLeftRadius="4dp"
android:topRightRadius="4dp"
android:bottomRightRadius="4dp"
android:bottomLeftRadius="4dp" />
<!--<stroke
android:width="1dp"
/>-->
</shape>

到这里就结束了,其实现方法很简单,大多数都写了注释,如果哪里有问题可随时联系我~

Xamarin.Android 制作搜索框的更多相关文章

  1. bootstrap制作搜索框及添加回车搜索事件

    下面是开发中用bootstrap制作的一个搜索框,以及给搜索框添加回车搜索事件的一个小案例. bootstrap制作搜索框及添加回车搜索事件 下面是功能实现的代码: <!DOCTYPE html ...

  2. android浮动搜索框

    android浮动搜索框的配置比较繁琐,需要配置好xml文件才能实现onSearchRequest()方法. 1.配置搜索的XML配置文件​,新建文件searchable.xml,保存在res/xml ...

  3. Android 系统搜索框(有浏览记录)

    实现Android 系统搜索框(有浏览记录),先看下效果: 一.配置搜索描述文件  要在res中的xml文件加创建sreachable.xml,内容如下: <?xml version=" ...

  4. Xamarin Android自定义文本框

    xamarin android 自定义文本框简单的用法 关键点在于,监听EditText的内容变化,不同于java中文本内容变化去调用EditText.addTextChangedListener(m ...

  5. xamarin android制作圆角边框

    xamarin android制作圆角边框 效果图如下: 关键代码: drawable文件夹新建shape_corner_down.xml <?xml version="1.0&quo ...

  6. Android 浮动搜索框 searchable 使用(转)。

    Android为程序的搜索功能提供了统一的搜索接口,search dialog和search widget,这里介绍search dialog使用.search dialog 只能为于activity ...

  7. Android actionbar 搜索框

    就是实如今顶部这种搜索框. 一.这个搜索框是actionbar上的menu上的一个item.叫SearchView.我们能够先在menu选项里定义好: bmap_menu.xml: <?xml ...

  8. Android的搜索框SearchView的用法-android学习之旅(三十九)

    SearchView简介 SearchView是搜索框组件,他可以让用户搜索文字,然后显示.' 代码示例 这个示例加了衣蛾ListView用于为SearchView增加自动补全的功能. package ...

  9. (转)Android SearchView 搜索框

    如果对这个效果感觉不错, 请往下看. 背景: 天气预报app, 本地数据库存储70个大中城市的基本信息, 根据用户输入的或通过搜索框选取的城市, 点击查询按钮后, 异步请求国家气象局数据, 得到返回的 ...

随机推荐

  1. FPGA學習筆記(貳)--- 流水燈

    平臺:FPGA黑金开发板 AX301 開發環境:Quartus Prime Version 17.0.0 Build 595 04/25/2017 Standard Edition 引脚配置:鼠標托拉 ...

  2. java的基本数据类型和引用类型

    一.基本数据类型: byte:Java中最小的数据类型,在内存中占8位(bit),即1个字节,取值范围-128~127,默认值0 short:短整型,在内存中占16位,即2个字节,取值范围-32768 ...

  3. Vue源码解析---数据的双向绑定

    本文主要抽离Vue源码中数据双向绑定的核心代码,解析Vue是如何实现数据的双向绑定 核心思想是ES5的Object.defineProperty()和发布-订阅模式 整体结构 改造Vue实例中的dat ...

  4. nodejs之使用express框架连接mysql数据库,返回jsonapi数据

    var express = require('express');var router = express.Router();var url = require('url');var mysql = ...

  5. JupyterLab绘制:柱状图,饼状图,直方图,散点图,折线图

    JupyterLab绘图 喜欢python的同学,可以到 https://v3u.cn/(刘悦的技术博客) 里面去看看,爬虫,数据库,flask,Django,机器学习,前端知识点,JavaScrip ...

  6. 配置Tomcat时遇到的问题

    今天准备开始JavaWeb的学习,先配置tomcat,前期一切顺利,可当我打开startup.bat,访问localhost:8080时,却显示localhost 拒绝了我们的连接请求. 于是我开始在 ...

  7. Unity2018 VS2017打开CS脚本,提示全红及无法加载工程等问题解决

    VS2017用的比较老的版本,因为当时下载了离线文件,所以可以离线安装,现在看来是没有必要的,占硬盘空间不说,不更新VS IDE,Unity高版本还有问题. 主要问题在于,我之前一直用Unity201 ...

  8. PageHelper分页+前台BootStrap_pagination样式/BootStrap_table样式

    一.PagerHelper分页+前台BootStrap_pagination样式: 效果: 1.引入pageHelper插件:2种方式    pageHelper所需jar包:pagehelper-5 ...

  9. 【转】像素 Pixel (Picture Element)

    原文链接:https://blog.csdn.net/zssureqh/article/details/78768942 1.像素Pixel 讲到概念,首选Wiki百科.当然我说的是英文版Pixel ...

  10. python列表和字符串的三种逆序遍历方式

    python列表和字符串的三种逆序遍历方式 列表的逆序遍历 a = [1,3,6,8,9] print("通过下标逆序遍历1:") for i in a[::-1]: print( ...