gpt4 book ai didi

android - 为什么我的 Action Bar 不叠加?

转载 作者:太空宇宙 更新时间:2023-11-03 11:13:37 25 4
gpt4 key购买 nike

我是 Android 开发新手。我已经在以下位置学习了 Android Overlay 培训:

http://developer.android.com/training/basics/actionbar/overlaying.html

并在过去的几天里努力让它发挥作用。我正在使用 AppCompat 库,我的最小 SDK 是 7,我的最大 SDK 是 18。

我的应用程序定义了一个自定义样式,如下所示:

<application

android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/CustomActionBarTheme" >

<activity
android:name="com.example.rtrt.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

我的布局是这样的:

<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"
tools:context=".MainActivity" >

<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/clickme"
android:onClick="sendMessage" />
</RelativeLayout>

我的 theme.xml 看起来像这样:

<style name="CustomActionBarTheme"  
parent="@style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style> <!-- ActionBar styles -->

<style name="MyActionBar"
parent="@style/Widget.AppCompat.Light.ActionBar">

<item name="android:background">@android:color/transparent</item>

<item name="android:windowActionBarOverlay">true</item>

<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
</style>

应用程序编译并运行...但是,Button 出现在ActionBar 下方(而不是下方)。当我隐藏 ActionBar 时,Button 移动到屏幕顶部。当 ActionBar 可见时,Button 将重新定位在屏幕下方。

为什么我的 ActionBar 没有 float (叠加)?

在此感谢任何帮助。

最佳答案

这是因为您的目标是低于 SDK 11。

将您的主题更改为 AppCompat 而不是 AppCompat.Light:

<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="@android:style/Theme.AppCompat">
<item name="android:windowActionBarOverlay">true</item>

<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
</style>

关于android - 为什么我的 Action Bar 不叠加?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20812933/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com