0

我有一个有背景的按钮我想在中心位置为按钮设置图标这是我的 xml 代码

        <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/imgbutton"
        android:layout_weight="1"
        android:layout_margin="10dp"
        android:fontFamily="cursive"
        android:textSize="30sp"
        android:drawableLeft="@drawable/lock"

但图标出现在按钮的左侧请帮助

可以将图标设置为用于多个按钮的形状吗?

4

5 回答 5

0

我想先有一个图标,然后单击图标替换为文本

将图标设为 imageButton,将我的文本设为 TextView。将它们设置在脱色位置。将文本的视图不透明度设置为 0(也称为透明)。并在图标上设置一个 onclick 侦听器以将文本视图的不透明度更改为 1,将图标更改为 0。

于 2018-05-10T00:11:55.320 回答
0

使用 ImageView 或 ImageButton 控件代替按钮。如果您只想显示图标或图像。

根据您的要求,使用 textview 和 imageview 并根据您的要求设置可见性。当您想显示图像集可见性->对imageview可见并设置可见性->转到textview时。反之亦然。

于 2018-05-10T09:07:10.057 回答
0

如果您只想使用图标(没有文字),那么您应该使用ImageButton

于 2018-05-09T21:06:56.523 回答
0

有几种方法可以做到这一点。

  1. 扩展 Button 类并在覆盖的类中提供自定义处理,然后在 XML 中使用它
  2. 使用RelativeLayout,然后将所有内容放入其中并切换他们应该看到的内容的可见性。添加点击处理程序
  3. 在布局上使用绑定进行可见性处理
  4. 使用自定义选择器,在它们与按钮交互时将中心内容换成可绘制或其他行为。

选择你的毒药,但有几十种方法可以剥去那只猫的皮。祝你好运。

于 2018-05-09T22:10:26.223 回答
0

使用ImageButton和设置 src 图像

<ImageButton
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="10dp"
        android:layout_weight="1"
        android:fontFamily="cursive"
        android:src="@drawable/lock"
        android:textSize="30sp" />
于 2018-05-10T06:42:55.320 回答