如何在 android 中给 Fragment TabHost 设置底部阴影?

How to give bottom shadow to FragmentTabHost in android?

您好,我想在我的片段中为我的 tabhost 设置阴影。我的 XML 密码是

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="60dip"
>
<android.support.v4.app.FragmentTabHost
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
   <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="0" />
</android.support.v4.app.FragmentTabHost>
<FrameLayout
    android:id="@+id/realtabcontent"
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="1" />
</LinearLayout>

我尝试了 Whosebug 上可用的所有解决方案,但它不起作用。请帮忙

Layer-list drawable是一种在背景中设置阴影效果的方法。

请按照此 link 为视图创建不同的可绘制对象并检查此 link 中提到的 View Box Shadows

Android中没有这个属性,要显示阴影。但可能的方法是:

  1. 添加一个简单的灰色 LinearLayout,在其上添加您的实际布局,底部边距为 1 或 2 dp

  2. 有一个带阴影的 9 补丁图像并将其设置为线性布局的背景

试试这个.. 创建 layout_shadow.xml 并放入 drawable 文件夹

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#CABBBBBB"/>
            <corners android:radius="2dp" />
        </shape>
    </item>

    <item
        android:left="0dp"
        android:right="0dp"
        android:top="0dp"
        android:bottom="2dp">
        <shape android:shape="rectangle">
            <solid android:color="@android:color/white"/>
            <corners android:radius="2dp" />
        </shape>
    </item>
</layer-list>

像这样应用到您的布局

 android:background="@drawable/layout_shadow"

选项卡宿主的最终布局

<android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:background="@drawable/layout_shadow"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

如果不行请告诉我

因为我使用的是 fragmenttabhost,所以无法操作它的视图。