我在photoshop cs6中设计了一个按钮并将其保存为png图像。当尝试在android studio中添加它作为imageView或imageButton时,它包含背景颜色。我试过android:backgroud="@android:color/transparent"
但没有运气。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="@+id/screenTextView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_weight="1"
android:background="#BDBDBD"
android:ems="10"
android:fadingEdge="none"
android:hint="0"
android:inputType="none"
android:textAlignment="viewEnd"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageButton
android:id="@+id/imageButton"
android:layout_width="0dp"
android:layout_height="160dp"
android:layout_weight="1"
android:background="@android:color/transparent"
app:srcCompat="@drawable/buttonn1" />
</LinearLayout>
编辑:https://github.com/Gamer1989/project/issues/1您可以在这里看到图像。
这适合我。如果它对你不起作用,你应该考虑到你的png有问题。您是否使用导入器将图像添加到您的项目?例如Batch Drawable Importer。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="@+id/screenTextView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_weight="1"
android:background="#BDBDBD"
android:ems="10"
android:fadingEdge="none"
android:hint="0"
android:inputType="none"
android:textAlignment="viewEnd"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageButton"
android:layout_width="match_parent"
android:layout_height="80dp"
android:padding="20dp"
android:src="@drawable/buttonn1" />
</LinearLayout>
</LinearLayout>
这意味着png文件没有透明背景。确保引用的文件具有此功能。这个link教会如何做到这一点。