【发布时间】:2019-03-11 11:20:23
【问题描述】:
我在 photoshop cs6 中设计了一个按钮并将其保存为 png 图像。当尝试将它作为 imageView 或 imageButton 添加到 android studio 中时,它包括背景颜色。我试过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 你可以从这里看到图片。
【问题讨论】:
-
发布图像或 XML 预览。我认为您只需要在 Photoshop 中更改它。
-
在 Photoshop 中,尝试“删除背景”橡皮擦
-
我添加了我的 xml 代码,但无法上传图片。在 photoshop 中,我的图像背景看起来是透明的。
-
U 正在使用 app:srcCompat= 来调用 png,但这对于矢量来说是特殊的。对于 png 你应该使用 android:src=,如果这有效果,请检查。
-
您可能会看到 ImageButton 的样式设置的背景。您可以只使用 ImageView 而不是 ImageButton。 ImageView 呈现您的图像没有按钮样式,并且具有相同的 onClick 事件
标签: android android-layout android-button