在应用内的选定活动上使用自定义标题栏

时间:2012-02-27 03:39:05

标签: android android-layout titlebar

好的,我会尽量详细说明。我有一个包含多个活动的应用程序。一些活动我想要一个自定义标题栏上有一个图像,然后是文本,然后图像按钮导航回到家(也就是主要活动)。我想要自定义标题栏的大多数页面都是列表视图页面。我已经连续加载了自定义标题栏,但它没有加载任何文本字段或图像只是标题栏中没有任何内容。这是我用过的代码。

window_title.xml

    <?xml version="1.0" encoding="utf-8"?>
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:background="#660000">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/icon72" />

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="0.39"
    android:gravity="right|center_vertical"
    android:paddingRight="5dip" >

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:text="@string/app_name"
        android:textColor="#FFFFFF"
        android:paddingRight="5dip" />

    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#660000"
        android:src="@drawable/home" />

    <ImageView
        android:id="@+id/home"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>

</LinearLayout>

custom_style.xml

     <resources>
<style name="CustomWindowTitleBackground">
    <item name="android:background">#660000</item>
</style>

<style name="CustomTheme" parent="android:Theme">
    <item name="android:windowTitleSize">50dip</item>
    <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>

Classes.Java

 import android.app.ListActivity;
 import android.content.Intent;
 import android.os.Bundle;
 import android.view.View;
 import android.view.Window;
 import android.widget.AdapterView;
 import android.widget.AdapterView.OnItemClickListener;
 import android.widget.ArrayAdapter;
 import android.widget.ListView;

 public class Classes extends ListActivity  {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);

        setListAdapter( new ArrayAdapter<String>(this, R.layout.ministries, list));

        ListView list = getListView();
        list.setTextFilterEnabled(true);
        list.setOnItemClickListener(new OnItemClickListener(){

我不确定我做错了什么或我需要做哪些更改,但我希望能够在某些活动中使用此自定义标题栏并在标题栏中加载该活动的名称。我看了几个教程,这两个有帮助,但我有点卡住了。 http://staticallytyped.wordpress.com/2011/03/18/android-dynamic-and-custom-title-bars/ 这个人帮助最多,我基本上遵循了 http://www.londatiga.net/it/how-to-create-custom-window-title-in-android/

感谢您提供任何帮助。我会发布图片,但还没有在这里得到那么远,所以再次感谢你的任何帮助

编辑 This is what i want it to look like this is what it looks like now in app

顶部图片是我希望标题栏看起来像什么,底部是它在应用程序中的样子

1 个答案:

答案 0 :(得分:1)

你可以使用android的include标签添加你的window_title.xml ....

参考: android include tag - invalid layout reference http://developer.android.com/resources/articles/layout-tricks-merge.html

相关问题