【发布时间】:2015-08-31 15:18:40
【问题描述】:
我的应用程序的背景图像有问题,我已将其设置为 android:background="@drawable/image_name" 并且在 android studio 的预览中工作正常,但是,当我运行应用程序,我看不到图像,只有白色背景,有人可以帮助我吗?
这是我的 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:background="@drawable/splash"
tools:context="com.example.ivan.posteggiaTI.LoginActivity">
<com.facebook.login.widget.LoginButton
android:id="@+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_above="@+id/editTextLoginEmail"
android:layout_centerHorizontal="true"
android:layout_marginBottom="48dp" />
<EditText
android:id="@+id/editTextLoginEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/login_edit_text"
android:hint="Email"
android:inputType="textEmailAddress"
android:paddingBottom="0dp"
android:paddingLeft="15dp"
android:paddingRight="10dp"
android:paddingTop="0dp"
android:textColor="#000000"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="22dp"
android:layout_above="@+id/editTextLoginPassword"
android:layout_alignParentStart="true" />
<EditText
android:id="@+id/editTextLoginPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/login_edit_text"
android:hint="Password"
android:inputType="textPassword"
android:paddingBottom="0dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="0dp"
android:textColor="#000000"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_above="@+id/textViewRegister"
android:layout_alignParentStart="true"
android:layout_marginBottom="34dp" />
<TextView
android:id="@+id/textViewRegister"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/button_blue_login"
android:gravity="center_vertical|center_horizontal"
android:text="Registrati"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff"
android:layout_alignTop="@+id/textViewLogin"
android:layout_toStartOf="@+id/textViewLogin" />
<TextView
android:id="@+id/textViewLogin"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/button_blue_login"
android:gravity="center_vertical|center_horizontal"
android:text="Login"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff"
android:layout_marginBottom="27dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" /></RelativeLayout>
【问题讨论】:
-
试过这段代码,在我的设备上运行良好,棒棒糖
-
尝试像这里stackoverflow.com/questions/12523005/…这样以编程方式从代码更改背景
-
哪个代码?你忘了...
-
@DavidBalas 我以这种方式尝试过
RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.relativeLayoutLogin); relativeLayout.setBackground(getResources().getDrawable(R.drawable.splash));但不起作用 -
您能告诉我启动图像的大小以及您将它保存在哪个可绘制文件夹中吗?
标签: android background-image drawable xml-drawable