FrameLayout 中的元素是不可见的

Elements in FrameLayout are invisible

我是 Android 开发的新手。 试图把Button和ImageView放在FrameLayout里面,但是它们是不可见的(它们确实存在于布局中,但没有绘制出来)。

我的布局:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/OuterFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foreground="@drawable/flb1_off">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/show_dialog"
        android:id="@+id/showDialogBtn"
        android:onClick="showDialog"
        android:layout_gravity="center"
        android:background="#123456"
        android:textColor="@color/abc_background_cache_hint_selector_material_dark"
        android:visibility="visible" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/flb"
        android:layout_gravity="bottom"
        android:contentDescription="@string/content_desc" />

</LinearLayout>

api 版本为 19。 有趣的是按钮clickHandler工作正常,但是按钮本身是不可见的。

如前所述,我将所有子项都设置为单个子项视图,但没有成功。

我做错了什么?

用 android:foreground 替换 android:background 修复了它,正如 SHAH MD MONIRUL ISLAM 提供的那样。

您的问题来自这一行:

android:foreground="@drawable/flb1_off"

你需要改变它。