我的 Activity 中有一个 ListView , Activity 的操作栏中设置为透明和向上导航。结果显示正确,但是第一项显示在 actionBAR 下方。如下图所示:
下面是我用来使栏透明的代码:
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
actionBar.setStackedBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setDisplayShowHomeEnabled(false);
setContentView(R.layout.invite_friends);
listView 的invite_friends.XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bluebackground"
android:orientation="vertical" >
<ListView
android:id="@+id/person_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector" />
</LinearLayout>
令人惊讶的是 ListView 认为它是全屏的?如何解决这个问题?
谢谢!
最佳答案
问题是这样的:
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
你正在告诉ActionBar
处于覆盖模式,这意味着它将覆盖内容而不是位于其上方的固定位置。如果您想动态隐藏和显示ActionBar
,这非常有用。在您的应用程序中,但不需要创建 ActionBar
透明的。只需将其删除,它就会按您的预期工作。
如果您想要或需要ActionBar
在覆盖模式下,您可以将填充应用于 Activity
中的内容等于 ActionBar
高度。像这样:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?android:attr/actionBarSize">
...
</RelativeLayout>
如果您使用支持库,则必须使用 ?attr/actionBarSize
安装了?android:attr/actionBarSize
像这样:
<!-- Support library compatibility -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize">
...
</RelativeLayout>
关于android - android 中的 ListView 和操作栏透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25078212/