简体   繁体   English

Android中的Listview和操作栏TRANSPARENT

[英]Listview and Action bar TRANSPARENT in android

I have a listview in my activity and Action bar for activity set to transparent and UP navigation. 我的活动和操作栏中有一个列表视图,用于将活动设置为透明和向上导航。 Results are showing up properly but, the first item is showing up below actionBAR. 结果显示正确,但是第一项显示在actionBAR下面。 Like the image below: 如下图所示:

查看下面的图片

Below is the code I am using to make the bar transparent: 以下是我用来使条形透明的代码:

    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 for listView: 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>

Surprising that the listview is thinking it is full screen? 令人惊讶的是,listview认为它是全屏的? How to solve this issue? 如何解决这个问题?

Thanks! 谢谢!

The problem is this: 问题是这样的:

getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);

You are telling the ActionBar to be in overlay mode, that means it will overlay the content instead of being at a fixed position above it. 您要告诉ActionBar处于叠加模式,这意味着它将覆盖内容,而不是位于其上方的固定位置。 This is useful if you want to dynamically hide and show the ActionBar in your app, but it is not required to make the ActionBar transparent. 如果您想在应用中动态隐藏和显示ActionBar ,但不需要使ActionBar透明,则这很有用。 Just remove it and it should work as you expect. 只需将其删除,它便会按预期工作。

If you however want or need the ActionBar in overlay mode than you can just apply a padding to the content in your Activity which is equal to the ActionBar height. 但是,如果您希望或需要叠加模式下的ActionBar ,则可以对Activity的内容应用等于ActionBar高度的填充。 Like this: 像这样:

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

If you are using the support library you have to use ?attr/actionBarSize insted of ?android:attr/actionBarSize like this: 如果您正在使用支持库,则必须使用?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