Java 设置背景图像
我已通过以下方式设置了我活动的背景:Java 设置背景图像,java,android,background,Java,Android,Background,我已通过以下方式设置了我活动的背景: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/image"> 我在做什么:在我的主要活动中,它将选择我是想要image1还是image2,
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/image">
我在做什么:在我的主要活动中,它将选择我是想要image1还是image2,然后将image1或image2作为活动的背景
谢谢使用
LinearLayout
方法setBackgroundResource
并为其提供可绘制id。使用LinearLayout
方法setBackgroundResource
并为其提供可绘制id。试试这个
LinearLayout linearLayout = (LinearLayout)findViewById(R.id.linear);
if(condition1)
linearLayout.setBackgroundResource(R.drawable.image1);
else
linearLayout.setBackgroundResource(R.drawable.image2);
在XML中
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id = "@+id/linear"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
这会奏效的。根据条件,它将设置image1或image2
LinearLayout linearLayout = (LinearLayout)findViewById(R.id.linear);
if(condition1)
linearLayout.setBackgroundResource(R.drawable.image1);
else
linearLayout.setBackgroundResource(R.drawable.image2);
在XML中
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id = "@+id/linear"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
这会奏效的。根据条件,它将设置image1或image2您尝试了什么?您将从何处选择图像?在下一个活动中显示该图像?您尝试了什么?您将从何处选择图像?在下一个活动中显示该图像?:)用户1330394:如果有效,则将其标记为正确答案:)用户1330394:如果有效,则将其标记为正确答案