Android自定义简单的顶部标题栏-创新互联

本文实例为大家分享了Android实现简单顶部标题栏的具体代码,供大家参考,具体内容如下

大竹网站建设公司成都创新互联公司,大竹网站设计制作,有大型网站制作公司丰富经验。已为大竹数千家提供企业网站建设服务。企业网站搭建\成都外贸网站建设要多少钱,请找那个售后服务好的大竹做网站的公司定做!

实现功能:

1)自定义View标题栏布局;

2)灵活的可以自己传入类型,选择所需要的控件来显示隐藏

3)相对于我之前写过的一篇,免继承,可直接在布局里使用

4)直接可以在布局控件里设置属性

老规矩,上几张效果图:

由效果图可见,这个是可以根据传入type来控制,比较灵活的

下面就来实现以下步骤,最后我会贴上源码

1.创建一个布局文件,命名,layout_titlebar,来部署我们的标题栏样式,可以自定义更改,图片文件可暂时用自己的替代

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="50dp">
 
  <ImageView
    android:id="@+id/iv_back"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:layout_marginLeft="20dp"
    android:src="@drawable/icon_back"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
 
  <TextView
    android:id="@+id/tv_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="标题"
    android:textColor="#000"
    android:textSize="16sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
 
  <TextView
    android:id="@+id/tv_more"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="更多"
    android:textColor="#000"
    android:textSize="16sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
 
  <ImageView
    android:id="@+id/iv_more"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:src="@drawable/icon_more"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
 
</android.support.constraint.ConstraintLayout>

当前标题:Android自定义简单的顶部标题栏-创新互联
URL地址:https://www.cdcxhl.com/article36/dssopg.html

成都网站建设公司_创新互联,为您提供定制开发小程序开发网站维护建站公司域名注册网站设计

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都网页设计公司