【Android】安卓开发实战之通过visibility属性实现搜索框弹出效果
来源:互联网 发布:自学java如何找工作 编辑:程序博客网 时间:2024/05/20 11:48
有时候我们可能会在APP顶部设置一个搜索图标,点击该图标,在顶部弹出一个搜索框,并将原标题栏覆盖,这个效果,我们可以通过使用visibility属性可简单实现。
先看一下效果图:
实现方法如下:
1、在大的布局里,再新建两个小的线性布局,第一个布局装着EditText搜索框、“取消”TextView,线性布局的visibility属性设置为gone,即不可见。
第二个线性布局里,装着“分类”ImageView、“联系人”TextView、搜索图标ImageView,线性布局2的visibility属性设置为visible,即可见。
这样就实现了,初始状态下,线性布局1不可见,线性布局2可见的效果。
<LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/rectangle_width" android:background="@color/theRed" android:gravity="center" android:visibility="gone" android:id="@+id/ll_of_search" > <EditText android:id="@+id/edit_of_search" android:layout_width="match_parent" android:layout_height="@dimen/rectangle_search_width" android:hint="@string/input_search_content" android:background="@drawable/round_white_box" android:layout_weight="1" android:layout_marginLeft="@dimen/search_margin_dimen" android:layout_marginRight="@dimen/search_margin_dimen" android:paddingLeft="@dimen/normal_padding_margin" android:textSize="16sp" android:imeOptions="actionDone" android:drawableLeft="@drawable/redsearch" android:singleLine="true" /> <TextView android:id="@+id/textView_search_cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/cancel" android:layout_marginLeft="@dimen/search_margin_dimen" android:layout_marginRight="@dimen/normal_padding_margin" android:textSize="18sp" android:textColor="@color/white" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/rectangle_width" android:background="@color/theRed" android:visibility="visible" android:id="@+id/ll_of_LinkMan" > <ImageView android:layout_width="@dimen/titleImage" android:layout_height="wrap_content" android:id="@+id/m_sortImageId" android:src="@drawable/sort" android:layout_marginLeft="@dimen/titleRetract" /> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="@string/linkman" android:gravity="center" android:textColor="@color/white" android:textSize="@dimen/titleTextSize" android:layout_weight="1" /> <ImageView android:layout_width="@dimen/titleImage" android:layout_height="wrap_content" android:src="@drawable/search" android:id="@+id/m_searchImageId" android:layout_marginRight="@dimen/titleRetract" /> </LinearLayout>2、在Java代码中监听搜素图标和“取消”文本的状态,通过setVisibility方法切换两个线性布局的可见状态即可。
@Override public void onClick(View view) { switch (view.getId()) { case R.id.m_searchImageId://点击“搜索”图标触发的事件 ll_Linkman.setVisibility(View.GONE); ll_searchman.setVisibility(View.VISIBLE); //---------------------------设置引入图片的尺寸--------------------------------------------- Drawable searchPic = getResources().getDrawable(R.drawable.redsearch); searchPic.setBounds(0, 0, 40, 40); searchEdit.setCompoundDrawables(searchPic, null, null, null); //------------------------------------------------------------------------------------------ break; case R.id.m_sortImageId://点击“组别”图标触发的事件 dialogOfGroup.show();//显式组别列表框 break; case R.id.textView_search_cancel://点击“取消”字样触发的事件 ll_Linkman.setVisibility(View.VISIBLE); ll_searchman.setVisibility(View.GONE); searchEdit.setText("");//清空输入框的内容 break; default: break; } }
0 0
- 【Android】安卓开发实战之通过visibility属性实现搜索框弹出效果
- 【Android】安卓开发实战之使用Fragment(碎片)实现底部导航栏效果
- 安卓开发20:动画之Animation 详细使用-主要通过java代码实现动画效果
- 安卓开发20:动画之Animation 详细使用-主要通过java代码实现动画效果
- 安卓开发20:动画之Animation 详细使用-主要通过java代码实现动画效果
- Android开发(17)-通过安卓API的Tabs3实现仿优酷tabhost效果
- Android开发(17)-通过安卓API的Tabs3实现仿优酷tabhost效果
- 安卓开发之搜索框功能
- 实现类似安卓市场搜索效果
- 【Android】安卓开发之通过本地广播实现子线程和UI线程的通信
- 安卓开发之编辑框属性
- 【Android】安卓开发实战之使用layout_weight优化布局
- 【Android】安卓开发实战之软键盘设置
- 安卓开发笔记 通过AlertDialog实现从底部弹出的菜单的代码编写
- android之visibility的三个属性
- weex开发实战(5)--利用wxc-tabbar实现类似安卓fragment分页效果
- Android开发之安卓属性动画大总结
- 【Android】安卓开发实战之自定义EditText输入框形状颜色
- Glide简单使用(二)
- java操作mongodb——查询数据
- SVN服务器搭建和使用(一)
- MySQL学习(二)DDL 加强 操作数据库的,操作表但不操作表的内部
- 数学符号和数学公式
- 【Android】安卓开发实战之通过visibility属性实现搜索框弹出效果
- tensorflow 关于张量 shape 数组
- php 防止sql注入
- SVN服务器搭建和使用(二)
- Resolve
- Linux常见问题
- Java 字节码操控框架ASM(四):Tools
- fastdfs-分布式存储设计指导(三)
- [OpenCV Qt教程] 在Qt图形界面中显示OpenCV图像的OpenGL Widget (第一部分)