如何通过按钮上的xml进行外部发光? [英] How to do an outer glow via xml on button?

查看:49
本文介绍了如何通过按钮上的xml进行外部发光?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有圆角的自定义按钮,在按下按钮时会放一些阴影,但是我想在按钮的底部做一​​个外部阴影,我正在通过xml进行绘制,因此如果发光可以那样的话会很棒.这些是代码的相关部分:

I have a customized button with rounded corners, I put some shadow for when it's pressed but I want to do an outer shadow just to the bottom part of the button, I am making the drawable via xml, so if the glow could be that way would be great. These are the relevant parts of the code:

button_pressed_shadows.xml

button_pressed_shadows.xml

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape android:shape="rectangle" >
           <gradient 
               android:startColor="@color/black_overlay"
               android:endColor="@color/btn_login"
               android:angle="270"/>
           <corners android:radius="4dip" />
        </shape>
    </item>

    <item               
        android:top="2px">
        <shape android:shape="rectangle"> 
            <solid android:color="@color/btn_login"/>
            <corners android:radius="4dip" />
         </shape>
    </item>
</layer-list>

style_login.xml

style_login.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
          android:drawable="@drawable/button_pressed_shadows" /> <!-- pressed -->
    <item android:state_focused="true"
          android:drawable="@drawable/button_focused" /> <!-- focused -->
    <item android:state_hovered="true"
          android:drawable="@drawable/button_focused" /> <!-- hovered -->
    <item android:drawable="@drawable/button_login" /> <!-- default -->
</selector>

推荐答案

由于我在photoshop上进行了按钮设计,因此我制作了一个9补丁图像,并将其放在样式选择器上,一切正常,认为是更好(最简单)的方式.

Since I have the button design on photoshop, I made a 9 patch image with it, and put it on the style selector, everything went fine, think is the better (easiest) way.

这篇关于如何通过按钮上的xml进行外部发光?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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