Change background image - Android
I have main.xml file where is my background file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:background="@drawable/backgroundfile"
In another activity xml file there is the same "backgroundfile".
I'd like to know if there is possibility to define one background file to all activities. I am going to create new activity where user will开发者_如何学编程 choose background for the whole app. Is it possible? Can you give me some clues?
Thank you for help. Excuse me for language mistakes.
if you are asking can we use same background image in background for all the activities then it is yes or if you want to use single xml file for all the activities as the background file then you can use this xml in your activity xml file like this:
<include
android:id="@+id/your_id"
layout="@layout/your_xml_filetoset" />
for that you have to set background at runtime and the value of the background will stored in shared preference, in onCreate() of all activity check the preference background value and set the same
Yes, it's possible..
it's some sort of source..
public void onClick(View v){
switch (v.getId()){
case R.id.IVImage1:
display.setImageResource(R.drawable.back_ah);
toPhone = R.drawable.back_ah;
break;
case R.id.IVImage2:
display.setImageResource(R.drawable.back_after_boom);
toPhone = R.drawable.back_after_boom;
break;
case R.id.bSetWallpapper:
Bitmap whatever = BitmapFactory.decodeStream(getResources().openRawResource(toPhone));
try{
getApplicationContext().setWallpaper(whatever);
} catch(IOException e){
e.printStackTrace();
}
}
精彩评论