搜索框的制作

一、整体布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"    
    xmlns:tools="http://schemas.android.com/tools"    
    android:layout_width="match_parent"    
    android:layout_height="36dp"   
     android:layout_marginBottom="8dp"   
     android:layout_marginLeft="16dp"    
    android:layout_marginRight="16dp"    
    android:layout_marginTop="8dp"   
     android:gravity="center_vertical"    
    android:background="@drawable/search_box_bg">   
<ImageView        
    android:layout_width="wrap_content"        
    android:layout_height="match_parent"       
     android:paddingLeft="8dp"        
      android:paddingRight="8dp"       
      android:src="@mipmap/cp_ic_search"       
     android:scaleType="center"       
     tools:ignore="ContentDescription" />   
 <EditText       
     android:id="@+id/et_search"       
     android:layout_weight="1"      
    android:layout_width="0dp"     
     android:layout_height="match_parent"        
    android:background="@null"        
    android:gravity="center_vertical"        
    android:hint="@string/cp_hint_search_box"        
    android:textColorHint="@color/cp_gray"        
    android:inputType="text"        
    android:singleLine="true"        
    android:textColor="@color/cp_gray"       
     android:textSize="14sp"       
     tools:ignore="RtlHardcoded" />   
 <ImageView        
    android:id="@+id/iv_search_clear"        
    android:layout_width="wrap_content"        
    android:layout_height="match_parent"      
    android:paddingLeft="8dp"      
    android:paddingRight="8dp"        
    android:src="@mipmap/cp_ic_search_clear"       
     android:visibility="gone"        
    tools:ignore="ContentDescription" />
</LinearLayout>

二、相关资源

drawable/search_box_bg.xml

<?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">    
    <corners android:radius="6dp"/>    
    <solid android:color="@android:color/white"/>
</shape>

colors.xml

<color name="cp_gray">#8c8c8c</color>

strings.xml

<string name="cp_hint_search_box">请输入城市名或拼音</string>
<string name="cp_hot_city">热门城市</string>
<string name="cp_located_city">定位城市</string>
<string name="cp_located_failed">定位失败</string>
<string name="cp_locating">正在定位…</string>
<string name="cp_nothing_found">没有搜索结果~</string>
<string name="cp_select_city">选择城市</string>

图片

cp_ic_search.png

cp_ic_back.png

cp_ic_locate.png

cp_ic_search_clear.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容