android动作栏重叠问题

时间:2014-01-26 21:54:04

标签: android android-actionbar overlay android-support-library

所有,我厌倦了制作一个动作栏覆盖我的活动布局。我也使用支持库来支持android 2.1及以上版本,我的活动布局如下:

<!-- activity_display_message.xml in layout folder -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="?attr/actionBarSize"
    tools:context=".DisplayMessageActivity" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</RelativeLayout>

manifest.xml就像:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myfirstapp"
    android:versionCode="1"
    android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="19" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher">
    android:theme="@style/CustomActionBarTheme" >

    <!-- some code for main activity -->

    <activity
        android:name="com.example.myfirstapp.DisplayMessageActivity"
        android:label="@string/title_activity_display_message"
        android:parentActivityName="com.example.myfirstapp.MainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.myfirstapp.MainActivity" />
    </activity>
    </application>
</manifest>

定义styles.xml的{​​{1}}如下:

CustomActionBarTheme

现在应用<?xml version="1.0" encoding="utf-8"?> <resources> <!-- the theme applied to the application or activity --> <!-- Support library compatibility --> <!-- Setting values in the default namespace affects API levels 7-13 --> <style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar"> <item name="actionBarStyle">@style/MyActionBar</item> <item name="actionBarTabTextStyle">@style/MyActionBarTabText</item> <item name="actionMenuTextColor">@color/actionbar_text</item> <item name="windowActionBarOverlay">true</item> </style> <!-- ActionBar styles --> <style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"> <item name="background">@color/orange</item> <item name="titleTextStyle">@style/MyActionBarTitleText</item> </style> <!-- ActionBar title text --> <style name="MyActionBarTitleText" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"> <item name="android:textColor">@color/actionbar_text</item> <!-- The textColor property is backward compatible with the Support Library --> </style> <!-- ActionBar tabs text --> <style name="MyActionBarTabText" parent="@style/Widget.AppCompat.ActionBar.TabText"> <item name="android:textColor">@color/actionbar_text</item> <!-- The textColor property is backward compatible with the Support Library --> </style> </resources> 时的问题是,应该显示在CustomActionBarTheme TextView中的文本(从主活动传递)消失了,所以我猜它是不是由于覆盖文本消息的覆盖操作栏,所以任何人都知道如何解决问题?

欢呼声

1 个答案:

答案 0 :(得分:0)

我认为原因是没有显示您的文字并且为了解决您的问题,您应该为TextView设置保证金最高值:?attr/actionBarSize

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize" />

我希望你已经解决了问题,这是一个正确答案:)