android简单自定义搜索框
来源:互联网 发布:联通网络加速器 编辑:程序博客网 时间:2024/05/20 15:42
搜索功能类:
public class SearchBuilder { private LinearLayout search_bar; private TextView hint; public SearchBuilder(Activity context){ search_bar = (LinearLayout) context.findViewById(R.id.search_bar_id); hint = (TextView) context.findViewById(R.id.search_bar_text); } public SearchBuilder(View context){ search_bar = (LinearLayout) context.findViewById(R.id.search_bar_id); hint = (TextView) context.findViewById(R.id.search_bar_text); } //搜索按钮监听 public SearchBuilder QueryOnListener(View.OnClickListener listener){ if (search_bar.getVisibility() == View.VISIBLE){ search_bar.setOnClickListener(listener); } return this; } //设置提示内容 public SearchBuilder setHintText(String hintText){ if (hint.getVisibility() == View.VISIBLE){ hint.setText(hintText); } return this; }}
layout xml:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="40dp" android:paddingLeft="8dp" android:paddingRight="8dp" android:layout_weight="1"> <LinearLayout android:id="@+id/search_bar_id" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:paddingLeft="8dp" android:paddingRight="8dp" android:gravity="center" android:background="@drawable/text_rectangle_white"> <ImageView android:layout_width="24dp" android:layout_height="24dp" android:layout_gravity="center" android:background="@drawable/search"/> <TextView android:id="@+id/search_bar_text" android:text="seach test" android:paddingLeft="16dp" android:layout_weight="1" android:gravity="center|left" android:layout_width="wrap_content" android:layout_height="match_parent" /> </LinearLayout></LinearLayout>
text_rectangle_white:<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:useLevel="false"> <!-- 实心 --> <solid android:color="@color/white" /> <!-- 圆角 --> <corners android:radius="24dp" /> <!-- 边距 --> <padding android:bottom="1dp" android:left="1dp" android:right="1dp" android:top="1dp" /> <!--边框线--> <stroke android:width="0.5dp" android:color="@color/gray" /> <!-- 大小 --> <size android:width="96dp" android:height="16dp" /></shape>
0 0
- android简单自定义搜索框
- Android自定义搜索框
- Android 自定义搜索框
- android 自定义搜索 的简单实现
- 【Android自定义View实战】之自定义超简单SearchView搜索框
- android 自定义搜索框 + 搜索提示
- Android 自定义过滤搜索框
- Android 自定义过滤搜索框
- Android 自定义过滤搜索框
- Android 自定义过滤搜索框
- Android之自定义搜索框
- 自定义超简单SearchView搜索框
- iOS自定义简单的搜索框
- Android自定义View——自定义搜索框(SearchView)
- Android自定义View——自定义搜索框(SearchView)
- Android自定义View——自定义搜索框(SearchView)
- Android自定义View——自定义搜索框(SearchView)
- MOSS 2007 最简单的自定义搜索框 SearchBox
- c# invoke回调函数
- RPC,RMI,Web Services,JMS那点事
- c语言数据结构补齐原则
- 快速排序(Quick Sort)
- division of labor for the android Kernel/BSP development .
- android简单自定义搜索框
- iOS/Android 开发中常用的正则表达式
- LNMP源码安装
- Qt源代码使用Vs2013中VC编译器编译的流程
- 通过Nginx访问后端应用,ERR_CONTENT_LENGTH_MISMATCH 问题的解决
- mysql创建用户
- uva11762 Race to 1
- UNIX多线程编程(4) 线程私有变量
- 自定义流式布局