Android自定义标题栏
来源:互联网 发布:软件测试个人心得 编辑:程序博客网 时间:2024/06/04 00:35
创建一个Android工程,标题栏默认显示的是工程名,下面介绍如何自定义标题栏,我创建工程的MainActivity继承AppCompatActivity,效果图如下
首先在AndroidManifest.xml文件中把默认的标题隐藏,设置
android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.nii.orcale" > <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/Theme.AppCompat.Light.NoActionBar" > <activity android:name=".MainActivity" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>
再创建一个标题的布局文件,就叫做title_toolbar.xml,内容如下
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout_titlebar" android:layout_width="match_parent" android:layout_height="52dp" android:background="#ed4255"> <TextView android:id="@+id/text_title" android:layout_width="match_parent" android:layout_height="match_parent" android:ellipsize="marquee" android:gravity="center_horizontal|center" android:singleLine="true" android:text="@string/title" android:textColor="#ffffffff" android:textSize="20dp"/></RelativeLayout>
最后把这个布局加入到主的布局文件中
<include layout="@layout/title_toolbar"></include>
<?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="match_parent" android:orientation="vertical" tools:context="com.nii.orcale.MainActivity"> <include layout="@layout/title_toolbar"></include> <ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="wrap_content" > </ListView></LinearLayout>
0 0
- android自定义标题栏progressBar
- Android自定义标题栏
- 自定义android标题栏
- android实现自定义标题栏
- Android自定义标题栏
- Android 自定义标题栏
- Android 自定义标题栏
- Android自定义标题栏
- Android自定义标题栏
- android之自定义标题栏
- Android自定义标题栏
- Android 自定义标题栏运用
- Android 自定义标题栏
- android ListView+自定义标题栏
- Android 自定义标题栏
- Android:自定义标题栏
- Android Actionbar自定义标题栏
- 自定义Android标题栏TitleBar
- ffmpeg3 保存视频帧(tutorial01)
- Calendar中的常用的方法的使用
- Linux Shell sort排序常用命令
- poj2109 Power of Cryptography —— 技巧性(高精度+二分的方法还没写)
- Struts从2.1升级到2.3版本过程
- Android自定义标题栏
- TCP协议三次握手,四次挥手机制
- Android服务的基本使用1(启动服务)
- service(上)
- 1077_最大序列和
- volatile和锁的简单总结
- 关于eclipse项目导入android studio遇到的坑
- 无人驾驶:多种技术的集成
- Solr突出显示示例