ListView和操作栏在透明的android [英] Listview and Action bar TRANSPARENT in android

查看:128
本文介绍了ListView和操作栏在透明的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在为活动设置为透明和UP导航我的活动和操作栏列表视图。结果显示正常了,但,第一项是显示下面的ActionBar起来。像下面的图片:

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. Like the image below:

下面是code我使用,使透明的吧:

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为ListView控件:

invite_friends.XML for 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>

奇怪,列表视图是以为它是全屏?如何解决这个问题?

Surprising that the listview is thinking it is full screen? How to solve this issue?

谢谢!

推荐答案

问题是这样的:

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

如果您使用的是你必须使用 ATTR / actionBarSize insted的的支持库安卓?ATTR / actionBarSize 是这样的:

If you are using the support library you have to use ?attr/actionBarSize insted of ?android:attr/actionBarSize like this:

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

这篇关于ListView和操作栏在透明的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆