以编程方式设置不是mainActivity的另一个活动的背景图像

时间:2019-01-08 18:03:29

标签: android android-studio android-layout android-fragments android-intent

我是android编程的新手。我正在制作一个小型应用程序,在这个应用程序中,我有2个活动,即主要活动和由主要活动调用的第二个活动。我在drawable文件夹中有像图像这样的资源。我希望设置新活动的背景图像,该活动由mainActivity以可绘制文件夹中的图像进行编程调用。这可能吗?

1 个答案:

答案 0 :(得分:1)

在活动的Android xml中创建一个Imageview

<ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/iso" [//Please put your drawable name here]
        android:id="@+id/background"
        android:scaleType="fitXY"
        />

然后将这些行添加到您的活动中。

ImageView layout = (ImageView) findViewById(R.id.background);
layout.setBackgroundResource(R.drawable.iso// Same here);
相关问题