gpt4 book ai didi

android - 在按钮选择器中更改 drawableleft

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:40:16 25 4
gpt4 key购买 nike

我找到了这个问答 Is it possible to change the left drawable of a Button in Selector xml?它对我不起作用。我试过这个:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/blue_rounded_button" android:drawableLeft="@drawable/aj_share_button_drawableleft" android:state_pressed="true"/>
<item android:drawable="@drawable/blue_rounded_button_frame" android:drawableLeft="@drawable/aj_share_button_drawableleft" />
</selector>


<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/aj_share_button_white_icon" android:state_pressed="true"/>
<item android:drawable="@drawable/aj_share_button_blue_icon" />
</selector>

像这样设置选择器:

<Button android:id="@+id/button1" 
android:background="@drawable/aj_share_button_state"
android:drawableLeft="@drawable/aj_share_button_drawableleft" />

谁能告诉我如何让它工作?

最佳答案

我建议:您的按钮 xml:

<Button android:id="@+id/button1" 
android:background="@drawable/selector_aj_share_button_state"
android:drawableLeft="@drawable/selector_aj_share_button_drawableleft"
/>

selector_aj_share_button_drawableleft.xml(在你的 drawable 文件夹中)

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/aj_share_button_white_icon"/>
<item android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/aj_share_button_white_icon" />
<item android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/aj_share_button_white_icon" />
<item android:drawable="@drawable/aj_share_button_blue_icon"/>
</selector>

它现在适用于左侧可绘制对象。尝试对 selector_aj_share_button_state 做同样的事情。希望对您有所帮助!

关于android - 在按钮选择器中更改 drawableleft,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27267356/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com