添加与四角填充自定义按钮点击效果 [英] Adding a click-effect on a custom button with padded corners

查看:209
本文介绍了添加与四角填充自定义按钮点击效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图加我的XML创建按钮的点击效果。到目前为止,我得到了clickeffect运行,但我不能设法提供的点击效果相同的圆角我对未点击的按钮;它看起来太可怕了这种方式。在我的 gradient.xml 我提供的圆角相同imagelayout,但它似乎忽略此设置。

有人能指出我在正确的方向?

< --->


我的clickeffect.xml框:(box_with_click_effect.xml)

 <选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
<项目的android:state_focused =真
    机器人:STATE_ pressed =假
    机器人:可绘制=@绘制/ rounded_box/>
<项目的android:state_focused =真
    机器人:STATE_ pressed =真
    机器人:可绘制=@绘制/梯度/>
<项目的android:state_focused =假
    机器人:STATE_ pressed =真
    机器人:可绘制=@绘制/梯度/>
<项目机器人:可绘制=@绘制/ rounded_box/>
< /选择>


我的按钮抽拉-XML:(rounded_box.xml)

 <形状的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
   [固体机器人:色=@色/ my_orange/>
   <角落的an​​droid:半径=15px的/>
   <填充机器人:左=1DP机器人:顶部=1DP机器人:右=1DP机器人:底部=1DP/>
< /形状>


我gradient.xml的点击状态:(gradient.xml)

 <层列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
<项目>
   < - 这不起作用:<位图的android:SRC =@绘制/ rounded_box/>
           所以我试试这个: - >
   <形状的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
        [固体机器人:色=@色/ cocus_orange/>
        <角落的an​​droid:半径=15px的/>
        <填充机器人:左=1DP机器人:顶部=1DP机器人:右=1DP机器人:底部=1DP/>
    < /形状>
< /项目>
<项目>
    <形状的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
        <梯度机器人:角=90
            机器人:startColor =#880f0f10
            机器人:centerColor =#880d0d0f
            机器人:ENDCOLOR =#885d5d5e/>
    < /形状>
< /项目>
< /层列表>


解决方案

更改code这样:

 <层列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
<项目>
   < - 这不起作用:<位图的android:SRC =@绘制/ rounded_box/>
           所以我试试这个: - >
   <形状的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
        [固体机器人:色=@色/ cocus_orange/>
        <角落的an​​droid:半径=15px的/>
        <填充机器人:左=1DP机器人:顶部=1DP机器人:右=1DP机器人:底部=1DP/>
    < /形状>
< /项目>
<项目>
    <形状的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
        <梯度机器人:角=90
            机器人:startColor =#880f0f10
            机器人:centerColor =#880d0d0f
            机器人:ENDCOLOR =#885d5d5e/>            <角落
                机器人:半径=15px的/>
  < /形状>
< /项目>
< /层列表>

您可以使用本网站生成您的按钮:的Andr​​oid按钮制造商

i am trying to add a click-effect on my xml-created button. So far i got the clickeffect running, but i cant manage to supply the click-effect the same rounded corners i have on the unclicked button; it looks horrible this way. In my gradient.xml I am supplying the same imagelayout with the rounded corners, but it seems to ignore this setting.

Can someone point me in the right direction?

< --- >


my box with clickeffect.xml: (box_with_click_effect.xml)

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_focused="true" 
    android:state_pressed="false" 
    android:drawable="@drawable/rounded_box" />
<item android:state_focused="true" 
    android:state_pressed="true" 
    android:drawable="@drawable/gradient" />
<item android:state_focused="false" 
    android:state_pressed="true" 
    android:drawable="@drawable/gradient" />
<item android:drawable="@drawable/rounded_box" />
</selector>


my button-drawable-xml: (rounded_box.xml)

<shape xmlns:android="http://schemas.android.com/apk/res/android" >    
   <solid android:color="@color/my_orange"/>
   <corners android:radius="15px"/>
   <padding android:left="1dp" android:top="1dp" android:right="1dp" android:bottom="1dp" /> 
</shape>


my gradient.xml for the clicked-state: (gradient.xml)

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
   <!--  THIS DOESN'T WORK: <bitmap android:src="@drawable/rounded_box"/> 
           SO I TRY THIS:   -->
   <shape xmlns:android="http://schemas.android.com/apk/res/android" >   
        <solid android:color="@color/cocus_orange"/>
        <corners android:radius="15px"/>
        <padding android:left="1dp" android:top="1dp" android:right="1dp" android:bottom="1dp" /> 
    </shape>
</item>
<item>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <gradient android:angle="90" 
            android:startColor="#880f0f10" 
            android:centerColor="#880d0d0f" 
            android:endColor="#885d5d5e"/>
    </shape>
</item>
</layer-list>

解决方案

Change your code to this:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
   <!--  THIS DOESN'T WORK: <bitmap android:src="@drawable/rounded_box"/> 
           SO I TRY THIS:   -->
   <shape xmlns:android="http://schemas.android.com/apk/res/android" >   
        <solid android:color="@color/cocus_orange"/>
        <corners android:radius="15px"/>
        <padding android:left="1dp" android:top="1dp" android:right="1dp" android:bottom="1dp" /> 
    </shape>
</item>
<item>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <gradient android:angle="90" 
            android:startColor="#880f0f10" 
            android:centerColor="#880d0d0f" 
            android:endColor="#885d5d5e"/>

            <corners
                android:radius="15px" />
  </shape> 
</item>
</layer-list>

You can use this website to generate you buttons: android button maker

这篇关于添加与四角填充自定义按钮点击效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆