繁体   English   中英

Android中的Listview和操作栏TRANSPARENT

[英]Listview and Action bar TRANSPARENT in android

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM