为片段设置背景?

时间:2013-03-08 22:33:55

标签: android android-layout android-fragments

我在我的应用程序中使用片段,我必须更改FragmnetTabs中其中一个片段的Background。出于这个原因,我在该fragmnet的布局中设置了background,我在Graphical Layout的{​​{1}}中可以看到它正常工作。但是当我运行我的应用程序时,它会向我显示带有黑色背景的片段内容,而不是我设置的图像。我这样设置......

Eclipse

但是这个可用的东西并没有出现在应用程序中。可能是什么问题呢?任何帮助表示赞赏。谢谢!

修改

如果我尝试以下列方式设置背景,它可以正常工作。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:background="@drawable/bg" >
<RelativeLayout/>

为什么自定义图像没有显示,但是android颜色呢?

1 个答案:

答案 0 :(得分:1)

您可以尝试在代码中执行此操作。请致电RelativeLayout

yourRelativeLayout.setBackground(getActivity().getResources().getDrawable(R.drawable.YourImage));

相关问题