打开APP
未登录
开通VIP,畅享免费电子书等14项超值服
开通VIP
首页
好书
留言交流
下载APP
联系客服
Andorid 自定义标题栏
昵称11482448
>《Android》
2013.03.30
关注
效果如图:
先在strings.xml 中定义主题
[html]
view plain
copy
print
?
<
style
name
=
"customTitlebg"
>
<
item
name
=
"android:background"
>
@drawable/title_bg
</
item
>
</
style
>
<
style
name
=
"titlebar"
parent
=
"android:Theme"
>
<
item
name
=
"android:windowTitleSize"
>
40dp
</
item
>
<
item
name
=
"android:windowTitleBackgroundStyle"
>
@style/customTitlebg
</
item
>
</
style
>
在AndroidManifest.xml,application标签中改为使用我们自定义的主题
[html]
view plain
copy
print
?
<
application
android:icon
=
"@drawable/ic_launcher"
android:label
=
"@string/app_name"
android:theme
=
"@style/titlebar"
>
<
activity
android:name
=
".MainActivity"
...
下面是自定义标题栏的实现 title_bar.xml
[html]
view plain
copy
print
?
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
RelativeLayout
xmlns:android
=
"http://schemas.android.com/apk/res/android"
android:orientation
=
"horizontal"
android:layout_width
=
"fill_parent"
android:layout_height
=
"fill_parent"
>
<
ImageView
android:layout_width
=
"wrap_content"
android:layout_centerVertical
=
"true"
android:layout_height
=
"wrap_content"
android:src
=
"@drawable/title_home_normal"
/>
<
TextView
android:layout_width
=
"wrap_content"
android:layout_centerInParent
=
"true"
android:layout_height
=
"wrap_content"
android:textColor
=
"#000000"
android:text
=
"自定义标题栏"
/>
<
ImageView
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
android:layout_alignParentRight
=
"true"
android:layout_centerVertical
=
"true"
android:src
=
"@drawable/title_new_normal"
/>
</
RelativeLayout
>
最后修改Activity
[java]
view plain
copy
print
?
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
//声明使用自定义标题
setContentView(R.layout.tabhost);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
//自定义布局赋值
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报
。
打开APP,阅读全文并永久保存
查看更多类似文章
猜你喜欢
类似文章
【热】
打开小程序,算一算2024你的财运
android自定义style
【Android 应用开发】 ActionBar 样式详解
ANDROID L
Android 设置Activity透明
android如何阻止app
Android Theme 常见主题风格详解
更多类似文章 >>
生活服务
热点新闻
留言交流
回顶部
联系我们
分享
收藏
点击这里,查看已保存的文章
导长图
关注
一键复制
下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!
联系客服
微信登录中...
请勿关闭此页面
先别划走!
送你5元优惠券,购买VIP限时立减!
5
元
优惠券
优惠券还有
10:00
过期
马上使用
×