android:在中间设置标题栏

Sam*_* Z. 2 android android-titlebar

我使用style.I代码创建自定义标题来自http://labs.makemachine.net/2010/03/custom-android-window-title/

我还在标题栏中设置了图标,setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,R.drawable.title_logo); 可以在中间设置标题栏吗?如果可能的话,我想使用自定义样式进行设置.

编辑:我有检查代码http://andmobidev.blogspot.com/2010/01/centering-title-of-window.html 它在标题栏中没有图标时工作正常但是当设置图标我得到错误 java.lang.ClassCastException: android.widget.RelativeLayout 我有不知道窗口如何绘制标题栏,我已经检查了博客 http://android-developers.blogspot.com/2009/03/window-backgrounds-ui-speed.html

谢谢.

Sam*_* Z. 5

我可以找到真正的答案,最后我加载了新的布局,以便在Oncreate中标题栏设置标题条码

 final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

        setContentView(R.layout.main);
        if (customTitleSupported) {
            getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
                    R.layout.title_bar);
        }
        final TextView myTitleText = (TextView) findViewById(R.id.title_bar);
        if (myTitleText != null) {
            myTitleText.setText(R.string.title_ble_melem);

        }
Run Code Online (Sandbox Code Playgroud)

这是布局

<?xml version="1.0" encoding="utf-8" ?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linear" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    >
    <TextView
        android:id="@+id/title_bar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="title bar"
        android:layout_centerInParent="true"
        android:layout_marginLeft="5dip"
        android:textStyle="bold"
        android:textColor="#ffffff"
        android:textSize="20sp"
       />

     <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/title_bar"
        android:src="@drawable/ic_top_bar"

    />
    </RelativeLayout >
Run Code Online (Sandbox Code Playgroud)

非常感谢您的回复.