最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
安卓Android 自定义标题栏(title栏)实例
时间:2013-11-29 编辑:简简单单 来源:一聚教程网
第一步,向实现自定义标题栏,需要在onCreate方法里这样写
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
注意:
requestWindowFeature要在setContentView之前
getWindow().setFeatureInit最好在setContentView之后
第二步,就是写好自己的布局文件,实现标题栏的自定义。
不过我们会遇到一些问题,就是标题栏的高度不能自定义~下面就是解决办法~
下面通过实例来看一下如何实现。
1、 在layout下创建一个titlebtn.xml文件,内容如下:
代码如下 | 复制代码 |
xml version="1.0" encoding="utf-8"?> <<>RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal">
android:id="@+id/imageButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:background="#00000000" android:src="@drawable/prv"/>
android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="标题栏"/>
android:id="@+id/imageButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerInParent="true" android:background="#00000000" android:src="@drawable/next"/> |
修改style.xml文件
加入下面代码
代码如下 | 复制代码 |
name="CustomWindowTitleBackground"> name="android:background">#00cc00 name="test"parent="android:Theme"> name="android:windowTitleSize">50dp name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground |
加入到AndroidManifest
代码如下 | 复制代码 |
|
相关文章
- Android 自定义 view 控件实例 11-30
- sora软件价格介绍 02-22
- sora官网入口地址一览 02-22
- Sora生成的视频使用教程 02-22
- 《梦幻西游》元宵灯谜线索答案大全2024 02-22
- 《原神》有朋自远方来第一天通关攻略 02-22