0
所以我想让用户可以选择让自己的图片从库中更改程序背景。我有一个按钮,我将这些图像保存为位图,并尝试使用button.setBackgroundDrawable()来执行此操作,但它将图片放在按钮上,以便只能看到按钮文本,并且也不会使图片全屏显示。下面是我的一些代码:Android:改变程序背景与图库中的图像
if (bitmap != null) {
bitmap.recycle();
}
InputStream stream = getContentResolver().openInputStream(data.getData());
bitmap = BitmapFactory.decodeStream(stream);
stream.close();
BitmapDrawable ob = new BitmapDrawable(getResources(), bitmap);
button.setBackgroundDrawable(ob);
而且我有XML设置这样的:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
tools:context="com.example.proba.MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:onClick="pickImage"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="106dp"
android:layout_marginTop="192dp"
android:text="Button" />
预先感谢您。
太感谢你了,它的工作。我将不得不做一些测试,但看起来这是解决方案。 – Ivusic
请标记此答案正确,如果它帮助你.. – YourDevMinion
好吧,我做到了,这是我的新网站。 – Ivusic