机器人:在中间设置标题栏 [英] android:set title bar in middle

查看:185
本文介绍了机器人:在中间设置标题栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个使用style.I code一些来自的 http://labs.makemachine.net/2010/03/custom-android-window-title/

I create the custom title using the style.I code some from http://labs.makemachine.net/2010/03/custom-android-window-title/

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

I have also set the icon in title bar using the setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,R.drawable.title_logo); can it is possible to set the title bar in middle?if possible then I want set using the custom style.

编辑:我有检查code 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

i have check code http://andmobidev.blogspot.com/2010/01/centering-title-of-window.html it work fine when there no icon in title bar but when set the icon i get the error java.lang.ClassCastException: android.widget.RelativeLayout i have no idea how the window draw the title bar ,i have check the one of blog http://android-developers.blogspot.com/2009/03/window-backgrounds-ui-speed.html

感谢你。

推荐答案

我能找到真正的答案,最后我加载新的布局中心的标题栏   设置标题栏code中的onCreate

I can find the real answer, at last i load the new layout for center the title bar set title bar code in 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);

        }

下面是布局

<?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 >

非常感谢您的答复。

Thank you very much for response.

这篇关于机器人:在中间设置标题栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆