【发布时间】:2019-06-05 01:01:48
【问题描述】:
基本上所有 ImageButton 必须做的 (InactiveButton) 就是在按下时切换到图像。我不知道从哪里开始,因为我是 Android Studio 的新手。
我尝试过使用选择器类,但我不知道它应该完成什么。当我使用 public void buttonOnClick(View v) 等其他代码时,android studio 说它已被弃用?
XML 布局:
<ImageButton
android:id="@+id/InactiveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/button_default" />
编辑 1:我添加了以下代码,但仍然在第 52 行得到一个 "annotations are not allowed here" @override,并且 cannot resolve symbol v 在行53.
编辑 2:第 50 行的最终错误图像
【问题讨论】:
-
另一个建议,如果您的所有边距都具有相同的 dp,那么您可以直接使用 layout_margin = "8dp" 并且效果相同
标签: java android android-imagebutton