iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >Android 自定义标题栏的实例详解
  • 336
分享到

Android 自定义标题栏的实例详解

android自定义标题栏 2023-05-30 19:05:58 336人浏览 八月长安
摘要

 Android 自定义标题栏的实例详解开发 Android APP 经常会用到自定义标题栏,而有多级页面的情况下还需要给自定义标题栏传递数据。本文要点:自定义标题填充不完整自定义标题栏返回按钮的点击事件一、代码这里先介绍一下流程

 Android 自定义标题栏的实例详解

开发 Android APP 经常会用到自定义标题栏,而有多级页面的情况下还需要给自定义标题栏传递数据。

本文要点:

自定义标题填充不完整
自定义标题栏返回按钮的点击事件

一、代码

这里先介绍一下流程:

创建一个标题栏布局文件 mytitlebar.xml
2. 在style.xml中创建 mytitlestyle 主题
3. 创建类 CustomTitleBar
4. 在需要自定义标题栏的Activity的OnCreate方法中实例化 CustomTitleBar
5. 在 AndroidManifest.xml 对使用了自定义标题栏的Activity定义主题

定义一个自定义的标题栏布局 mytitlebar.xml

<?xml version="1.0" encoding="utf-8"?><RelativeLayout  android:id="@+id/re_title" xmlns:android="Http://schemas.android.com/apk/res/android"  android:layout_width="fill_parent"  android:layout_height="50dp" //定义自定义标题栏的高度  android:background="@color/start_background"  android:orientation="horizontal">  <ImageButton    android:scaleType="fitXY"    android:layout_alignParentLeft="true"    android:layout_centerVertical="true"    android:layout_marginLeft="10dp"    android:id="@+id/bt_back"    android:layout_width="25dp"    android:layout_height="25dp"    android:src="@drawable/left_back"    android:background="@color/touming"/>  <TextView    android:id="@+id/mytitle"    android:layout_centerInParent="true"    android:layout_width="wrap_content"    android:layout_height="match_parent"    android:gravity="center"//使文字在整个标题栏的中间    android:textColor="#fff"    android:textSize="20dp" /></RelativeLayout >

--结束END--

本文标题: Android 自定义标题栏的实例详解

本文链接: https://www.lsjlt.com/news/220723.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作