【问题标题】:Listview and Action bar TRANSPARENT in androidandroid中的Listview和Action bar TRANSPARENT
【发布时间】:2014-08-01 18:46:11
【问题描述】:

我的活动和操作栏中有一个列表视图,活动设置为透明和向上导航。结果显示正确,但第一项显示在 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);

invite_friends.XML 用于 listView:

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

令人惊讶的是列表视图认为它是全屏的?如何解决这个问题?

谢谢!

【问题讨论】:

标签: android listview


【解决方案1】:

问题是这样的:

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

【讨论】:

  • 是的,刚刚发现这个,似乎是罪魁祸首
  • 如果我删除 ACTION_BAR_OVERLAY.. 我的操作栏变成白色?我希望它是透明的?
  • 该标志与颜色无关。你一定是做错了什么。
  • 我在我的 xml 中添加了 android:paddingTop="?android:attr/actionBarSize" 它现在可以正常显示...谢谢!
  • 使用这种方法,如果您使用带有操作栏的快速返回模式(如 Google IO 2014 应用程序),您将在 ListView 中看到一个空白区域。我现在发现的唯一方法是在 ListView 中使用 2 种不同的单元格类型,第一个位置的单元格是一个与操作栏高度相同的空单元格。
猜你喜欢
  • 2014-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多