我怎样才能成为我的标题栏?

时间:2012-02-25 22:27:13

标签: android android-layout

我有一个标题栏我的项目之一,我想使用我的所有屏幕。我认为我可以成为一般(意味着我想要一些东西,我将在任何地方呼叫像样式标签或主题标签)我我不知道。我可以用什么?

我的标题栏在这里:

RelativeLayout
            android:layout_height="44dip"
            android:layout_width="320dip"
            android:background="@drawable/merhaba_header_320_44dip">
        <ImageView
            android:layout_height="32dip"
            android:layout_width="121dip"
            android:background="@drawable/merhaba_logo_121_32dip"
            android:layout_centerInParent="true">
        </ImageView>
        <ImageView
            android:layout_height="30dip"
            android:layout_width="64dip"
            android:background="@drawable/merhaba_btn_nedir_64_30dip"
            android:layout_margin="5dip"
            android:layout_alignParentRight="true">
        </ImageView>
    </RelativeLayout>

2 个答案:

答案 0 :(得分:0)

嗨DuyguK你是否想要一种方法来获得一个标题栏,你可以将其作为主题应用于你应用中的所有活动?

如果是这样,我会建议您执行以下操作。 首先在res / values / styles.xml中定义一个样式

<resources>
    <style name="MyTheme" parent="android:style/Theme.Light">
        <item name="android:windowTitleSize">44dip</item>
        //whatever item you want/need to edit for your custom title bar
    </style>
</resources>

这使您可以拥有适用于整个应用的主题。为此,您需要转到AndroidManifest.xml文件,在应用程序标记内添加以下内容:

<application android:label="@string/app_name"
    android:theme="@style/MyTheme">

android:theme告诉应用程序使用名为“MyTheme”的主题,该主题可以在项目的res / values / styles.xml文件中找到。 这样您就可以正确地将自定义标题栏应用于您的所有活动。 希望这能回答你的问题,如果没有,请注明!

另一个建议是查看Android SDK中示例附带的ActionBarCompat项目。 Android Developers页面显示项目:

http://developer.android.com/resources/samples/ActionBarCompat/index.html

它具有与API11之前设备兼容的优势,可作为主题应用于您的应用程序,并且正在商店中提供的许多应用程序中使用它。 如果您有任何问题/疑问,请告诉我。

答案 1 :(得分:0)

创建自己的风格,可以从现有主题的现有范围扩展。 将windowNoTitle更改为true。

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="noTitleBarStyle" parent="android:Theme.Black">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@color/darkGrey</item>   
<item name="android:colorForeground">#ff3333</item> 
</style></resources>