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个大中城市的基本信息, 根据用户输入的或通过搜索框选取的城市, 点击查询按钮后, 异步请求国家气象局数据, 得到返回的 ...
随机推荐
- python 10 迭代器和三元运算符
一.迭代器 1.迭代器协议:对象必须提供一种next方法,执行该方法要么返回迭代中的下一项,要么引起一个stopIteration异常,终止迭代 2.可迭代对象:实现了迭代器协议的对象 3.pytho ...
- Redis学习笔记:与SpringBoot结合使用
首先需要在pom文件中导入相应的Redis依赖(版本可以会变化,下面坐标也可能会变化) <dependency> <groupId>org.springframework.bo ...
- Java的xml与map,与Bean互转
xml与map互转,主要使用dom4j import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j. ...
- 第八周助教工作总结——NWNU李泓毅
1.助教博客链接: https://www.cnblogs.com/NWNU-LHY/ 2.作业要求博客链接: http://www.cnblogs.com/nwnu-daizh/p/10687492 ...
- 树莓派RaspBerry账户初始化设定
1 第一次安装系统进入后默认账户是pi/raspberry root账户是默认锁定的 sudo passwd root 设置root账户密码 sudo passwd --unlock root 开启 ...
- 关于浏览器cookie的小知识
浏览器对于总的cookie数量是没有限制的,但是对于每个域名的cookie数量是有限制的. 一,不同的浏览器,对于一个域名的cookie数量限制上限是不同的: 1,IE6以下版本,最多20个.IE7以 ...
- python模块:subprocess
# subprocess - Subprocesses with accessible I/O streams # # For more information about this module, ...
- drools规则引擎中易混淆语法分析_相互触发导致死循环分析
整理了下最近在项目中使用drools出现的问题,幸好都在开发与测试阶段解决了,未波及到prod. 首先看这样两条规则: /** * 规则1_set默认利率a */ rule "rate_de ...
- 2018-04-10 我的GitHub诞生的日子,欢迎大家吐槽批评
我的GitHub,诞生的日子,欢迎大家吐槽与批评,嘻嘻 首先是自己想刷一下LeetCode上的代码,其次创建了自己的读书笔记以及面试经验与教训 下边是仓库的Git链接,欢迎大家的批评与修正,谢谢: L ...
- 软件测试-chapter2-homework2
程序一 1.the fault:for循环中i>0应改为i>=0 for (int i=x.length-1; i >= 0; i--) 2. (Reachability可达性,是f ...