方法一、在你的那张Activity中onCreate方法中加上下面代码:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE)
setContentView(R.layout.main) //软件activity的布局
但是新的问题又来了,这样是无法深层的定制标题栏的,比如原有的高度和背景都没有发生变化,那有没有好的方法呢?答案是有的、
方法二:
因此先定义一个style,若修改背景请修改android:windowTitleBackgroundStyle
若修改标题栏高度,请修改android:windowTitleSize
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomWindowTitleBackground">
<item name="android:background">#565656</item>
</style>
<style name="test" parent="android:Theme">
<item name="android:windowTitleSize">50dp</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>
在程序的android_manifest.xml中对应activity中添加属性android:theme = "@style/test"
就可以了
<activity android:name=".Test"
android:theme = "@style/test" //就在这里
>
</activity>
之后借助于设置自定义的标题栏xml文件,就可以自定义标题栏布局了
mainifests中设置:android:theme="@style/AppTheme"(即默认设置).
⒉ values->styles.xml中设置:
style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar".
二values->styles.xml中:
在当先使用的style的parent属性添加NoActionBar.如原先为
style name="AppTheme" parent="Theme.AppCompat.Light".
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)