Android中实现自定义标题栏

Android中实现自定义标题栏

布局

<!--自定义标题栏,可以封装到view-->
    <RelativeLayout
        android:id="@+id/title_container"
        android:layout_width="match_parent"
        android:layout_height="@dimen/d45"
        android:paddingHorizontal="@dimen/d10"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/left_button"
            android:layout_width="@dimen/super_title_icon_width"
            android:layout_height="@dimen/super_title_icon_width"
            android:layout_centerVertical="true"
            android:padding="@dimen/d5"
            android:src="@drawable/menu" />

        <!--标题-->
        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="@dimen/d38"
            android:layout_centerVertical="true"
            android:layout_toLeftOf="@+id/right_button"
            android:layout_toRightOf="@+id/left_button"
            android:gravity="center"
            android:text="@string/me"
            android:textColor="?attr/colorOnSurface"
            android:textSize="18sp"
            android:textStyle="bold"
            android:visibility="gone" />

        <!--搜索容器-->
        <LinearLayout
            android:id="@+id/search_container"
            android:layout_width="wrap_content"
            android:layout_height="@dimen/d35"
            android:layout_centerVertical="true"
            android:layout_marginHorizontal="@dimen/padding_small"
            android:layout_toLeftOf="@+id/right_button"
            android:layout_toRightOf="@+id/left_button"
            android:background="@drawable/shape_input"
            android:gravity="center"
            android:orientation="horizontal">

            <!--
            app:tint:对src图着色,矢量图,普通都可以,但推荐是单色
            因为不是单色的,原图不同的颜色都变成一种颜色了
            好处是不用放多张不同颜色的图片-->
            <ImageView
                android:layout_width="@dimen/d20"
                android:layout_height="@dimen/d20"
                android:src="@drawable/search"
                app:tint="@color/black80" />

            <TextView
                android:id="@+id/search"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:hint="@string/hint_search_value"
                android:minHeight="@dimen/d40"
                android:padding="@dimen/d5"
                android:textColor="@color/black80"
                android:textSize="@dimen/s15" />
        </LinearLayout><!--/搜索容器-->

        <ImageView
            android:id="@+id/right_button"
            android:layout_width="@dimen/super_title_icon_width"
            android:layout_height="@dimen/super_title_icon_width"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:padding="@dimen/d5"
            android:src="@drawable/mic" />
    </RelativeLayout>
    <!--/自定义标题栏-->

事件

//打开侧滑按钮点击
binding.leftButton.setOnClickListener(v -> {
});

//搜索容器点击
binding.searchContainer.setOnClickListener(v -> {

});
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值