我用以下内容创建了一个自定义标题栏。
myapptitle.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myTitle"
android:text="@string/app_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/titletextcolor"
android:textSize="14sp"
android:layout_gravity="top"
/>
themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="customTheme" parent="android:Theme">
<item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground</item>
<item name="android:windowTitleSize">40dip</item>
</style>
</resources>
manifext.xml
<application
android:label="@string/app_name"
android:theme="@style/customTheme" >
.....
我已经创建了一个customList adapater和一个类似下面的布局。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/icon"
android:layout_width="22dip"
android:layout_height="22dip"
android:layout_marginLeft="4dip"
android:layout_marginRight="10dip"
android:layout_marginTop="4dip"
android:contentDescription="@string/app_msg_title"
android:src="@drawable/logo_small" >
</ImageView>
<TextView
android:id="@+id/msgDate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="14sp"
/>
<TextView
android:id="@+id/msgTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="14sp" />
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+id/label"
android:textSize="12sp" >
</TextView>
</LinearLayout>
在清单活动中,我在onCreate方法中提供了以下代码。
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.myapptitle);
但是以某种方式在运行应用程序时,我得到的标题栏根本没有任何文本。在我的app_name的strings.xml中,我的通知为文本。
感谢您的所有时间和帮助。
编辑的 Styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="WindowTitleBackground">
<item name="android:background">@color/titlebackgroundcolor</item>
</style>
</resources>
如下更改您的style.xml:
<resources>
<style name="CustomWindowTitleBarBG">
<item name="android:background">#323331</item>
</style>
<style name="TitleBarTheme" parent="android:Theme">
<item name="android:windowTitleSize">35dip</item>
<item name="android:windowTitleBackgroundStyle"> @style/CustomWindowTitleBarBG</item>
</style>
</resources>
然后
在清单文件中,在应用程序标记中使用TitleBarTheme,并为活动使用,如下所示:
android:theme="@android:style/Theme.NoTitleBar"
在活动课中,使用您的代码:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.myapptitle);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句