您的位置:首页 > 移动开发 > Android开发

android自定义标题的相关问题

2014-10-09 21:08 295 查看
一.在完成下面几步之后

1. 创建自定义标题栏的xml文件,可以给标题栏加背景(引用图片或者在drawable文件下通过xml文件生成);

2.在activity中通过requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);// 声明使用自定义标题

3.setContentView(R.layout.activity_login);//加载主界面

4. getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);

// 添加自定义布局

如果出现you cannot combine custom titles with other title features这个运行时异常,请检查values下的styles.xml文件中

是否有

<style name="AppTheme" parent="AppBaseTheme">

<item name="android:windowActionBar">false</item>

</style>

很多项目初建时<item name="android:windowActionBar">false</item> 是没有的。

二:自定义标题没有铺满宽度,这个已经有很多大手解释并给出了操作步骤,此处不做说明

三:自定义标题的高度问题,发现即使在styles.xml中配置了

<item name="android:windowTitleSize">100dp</item>

如果自定义的标题栏xml只有文本,如:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

>

<TextView

android:layout_width="wrap_content"

android:layout_height="match_parent"

android:text="@string/content" />

</LinearLayout>

那么高度还是一点点高,实验发现是跟TextView的高度一致的。

如果想要高度改变,可以将LinearLayout 的高度设置成100dp,跟<item name="android:windowTitleSize">100dp</item>的值保持一样即可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: