Xamarin.Android 制作搜索框
前段时间仿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 制作搜索框的更多相关文章
- bootstrap制作搜索框及添加回车搜索事件
下面是开发中用bootstrap制作的一个搜索框,以及给搜索框添加回车搜索事件的一个小案例. bootstrap制作搜索框及添加回车搜索事件 下面是功能实现的代码: <!DOCTYPE html ...
- android浮动搜索框
android浮动搜索框的配置比较繁琐,需要配置好xml文件才能实现onSearchRequest()方法. 1.配置搜索的XML配置文件,新建文件searchable.xml,保存在res/xml ...
- Android 系统搜索框(有浏览记录)
实现Android 系统搜索框(有浏览记录),先看下效果: 一.配置搜索描述文件 要在res中的xml文件加创建sreachable.xml,内容如下: <?xml version=" ...
- Xamarin Android自定义文本框
xamarin android 自定义文本框简单的用法 关键点在于,监听EditText的内容变化,不同于java中文本内容变化去调用EditText.addTextChangedListener(m ...
- xamarin android制作圆角边框
xamarin android制作圆角边框 效果图如下: 关键代码: drawable文件夹新建shape_corner_down.xml <?xml version="1.0&quo ...
- Android 浮动搜索框 searchable 使用(转)。
Android为程序的搜索功能提供了统一的搜索接口,search dialog和search widget,这里介绍search dialog使用.search dialog 只能为于activity ...
- Android actionbar 搜索框
就是实如今顶部这种搜索框. 一.这个搜索框是actionbar上的menu上的一个item.叫SearchView.我们能够先在menu选项里定义好: bmap_menu.xml: <?xml ...
- Android的搜索框SearchView的用法-android学习之旅(三十九)
SearchView简介 SearchView是搜索框组件,他可以让用户搜索文字,然后显示.' 代码示例 这个示例加了衣蛾ListView用于为SearchView增加自动补全的功能. package ...
- (转)Android SearchView 搜索框
如果对这个效果感觉不错, 请往下看. 背景: 天气预报app, 本地数据库存储70个大中城市的基本信息, 根据用户输入的或通过搜索框选取的城市, 点击查询按钮后, 异步请求国家气象局数据, 得到返回的 ...
随机推荐
- python11 装饰器与闭包
一.装饰器定义 本质:一种函数,为其他函数增加新功能 原则: 1.不修改被修饰函数的源代码 2.不修改被修饰函数的调用方式 需要技能:装饰器=高阶函数+函数嵌套+闭包 二.高阶函数 定义:函数接收的参 ...
- 笔记javascript
// var demo1=12;// alert('点击确定按钮看结果'+demo1);// for(var i = 0; i<10;i++)// {// document.write( ...
- NOVO SOP (SOP简介及历史)
SOP(Standard Operation Procedure),标准作业程序. 一.什么是SOP(标准作业程序) 所谓SOP,是 Standard Operation Procedure三个单词中 ...
- Scrum冲刺阶段6
成员今日完成的任务 人员 任务 何承华 学习后端设计 陈宇 后端设计 丁培辉 学习后端设计 温志铭 信息界面设计 杨宇潇 信息界面界面设计 张主强 服务器构建学习 成员遇到的问题 人员 问题 何承华 ...
- HCNA之网络通信基础
一.通信与网络 通信的概念我们并不陌生,在人类社会的起源和发展过程中,通信就直伴随着我们.般认为, 20世纪七.八十年代,人类社会已进入到信息时代,对于生活在信息时代的我们,通信的必要性和重要性更是不 ...
- ehcache如何配置
1.pom.xml文件配置(主要针对jar包的引入) <ehcache.version>2.6.9</ehcache.version><ehcache-web.versi ...
- java 幂等性(转)
(转自)http://www.cnblogs.com/weidagang2046/archive/2011/06/04/idempotence.html 理解HTTP幂等性 基于HTTP协议的Web ...
- 处理Word文档中所有修订
打开现有文档进行编辑 若要打开现有文档,您可以将 Word类实例化,如以下 using 语句所示. 为此,您可以使用Open(String, Boolean) 方法打开具有指定 fileName 的字 ...
- XSS攻击 CSRF攻击
XSS攻击: 跨站脚本攻击(Cross Site Scripting),为不和层叠样式表(Cascading Style Sheets, CSS)的缩写混淆, 故将跨站脚本攻击缩写为XSS.恶意攻击者 ...
- 随便写写,也有一些参考了我jio的很好的他人的成果
Spring框架学习记录(1) 一. https://www.cnblogs.com/yuanqinnan/p/10274934.html (一)只要用框架开发java,一定躲不过spring,Spr ...