直播软件开发,自定义搜索栏的图标样式和搜索框

直播软件开发,自定义搜索栏的图标样式和搜索框实现的相关代码

一.引入布局

如果在每一个Activity的布局中都编写一个搜索栏,会导致代码的重复。通过采用引入布局的形式,可以解决这个问题。

首先在layout目录下创建一个select.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="50dp"
    android:background="@drawable/back001">
    <ImageView
        android:id="@+id/select_p01"
        android:layout_marginTop="2dp"
        android:layout_width="46dp"
        android:layout_height="41dp"
        android:src="@drawable/select_photo01" />
    <EditText
        android:id="@+id/select01"
        android:layout_marginTop="6dp"
        android:layout_width="250dp"
        android:layout_height="35dp"
        android:layout_marginLeft="10dp"
        <!--采用edittext_shap01样式-->
        android:background="@drawable/edittext_shape01"/>
    <ImageButton
        android:id="@+id/select_p02"
<!-- 清除按钮背景-->
        style="?android:attr/borderlessButtonStyle"
        android:layout_marginTop="0dp"
        android:layout_width="53dp"
        android:layout_height="50dp"
<!-- fitXY 的作用是“保持图片长宽比例”-->
        android:scaleType="fitXY"
        android:src="@drawable/select_photo02" />
</LinearLayout>

二.布局解析

此处对上方的布局进行补充:

1.设置布局背景为back001

 


android:background="@drawable/back001"

2.导入图片select_photo01

为了使搜索栏不单调,故导入图片装饰

 


android:src="@drawable/select_photo01" 

3.采用edittext_shape01样式

系统自带的EditText仅是一条直线,此处将其变成圆型输入框

android:background="@drawable/edittext_shape01"

edittext_shape01代码如下:

 


<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <solid
        android:color="#FFFFFF" >
    </solid>
    <!-- 设置圆角 -->
    <corners
        android:radius="3dp"
        android:bottomLeftRadius="15dp"
        android:bottomRightRadius="15dp"
        android:topLeftRadius="15dp"
        android:topRightRadius="15dp" >
    </corners>
    <!-- 设置边框 -->
    <stroke android:width="1dip" android:color="#ff000000" />
</shape>

4.导入图片select_photo02装饰

 


android:scaleType="fitXY"
android:src="@drawable/select_photo02" 

​以上就是 直播软件开发,自定义搜索栏的图标样式和搜索框实现的相关代码,更多内容欢迎关注之后的文章

 

posted @ 2022-03-07 14:09  云豹科技-苏凌霄  阅读(112)  评论(0)    收藏  举报