删除/添加动态阴影效果 [英] Remove/add shadow effect dynamically

查看:154
本文介绍了删除/添加动态阴影效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的按钮禁用我需要删除的文字阴影效果,当按钮使我需要重新添加这种效果。

selector_btn.xml

 <选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android><项目
    机器人:可绘制=@绘制/ btn_disabled
    机器人:state_enabled =FALSE/><项目
    机器人:可绘制=@绘制/ btn_ pressed
    机器人:STATE_ pressed =真/><项目
    机器人:可绘制=@绘制/ btn_default/>

styles.xml

 <样式名称=TextShadow>
    <项目名称=机器人:文字颜色>#FFFFFFFF< /项目>
    <项目名称=安卓则shadowColor>#0D67B9< /项目>
    <项目名称=机器人:shadowRadius> 2.0< /项目>
    <项目名称=机器人:shadowDy>&-2.0 LT; /项目>
< /风格><样式名称=BigButton父=TextShadow>
    <项目名称=机器人:背景> @绘制/ selector_btn< /项目>
< /风格>


解决方案

 你必须做2不同模式样式启用和禁用状态并将其应用于TextView的时候禁用或反之亦然.. 。
            <样式名称=TextShadow_disable>
              <项目名称=机器人:文字颜色>#FFFFFFFF< /项目>
               <项目名称=安卓则shadowColor>#0D67B9< /项目>
              <项目名称=机器人:shadowRadius> 0℃; /项目>
             <项目名称=机器人:shadowDy> 0℃; /项目>
              < /风格>
             <样式名称=TextShadow_enable>
              <项目名称=机器人:文字颜色>#FFFFFFFF< /项目>
             <项目名称=安卓则shadowColor>#0D67B9< /项目>
             <项目名称=机器人:shadowRadius> 2.0< /项目>
             <项目名称=机器人:shadowDy>&-2.0 LT; /项目>
            < /风格>          文字样式=(的TextView)findViewById(R.id.mytext);
          textstyle.setOnClickListener(新OnClickListener(){                @覆盖
                公共无效的onClick(视图v){
                    getTextStyle();                }
            });

写下此方法来检查启用禁用;

 公共无效getTextStyle(){
           如果(textstyle.isEnabled()){
                 textstyle.setTextAppearance(这一点,R.style.TextShadow_enable);
                }
             其他{
                   textstyle.setTextAppearance(这一点,R.style.TextShadow_disable);
                }
          }

When my button disabled i need remove text shadow effect and when button enable I need add this effect again.

selector_btn.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item
    android:drawable="@drawable/btn_disabled"
    android:state_enabled="false" />

<item
    android:drawable="@drawable/btn_pressed"
    android:state_pressed="true" />

<item
    android:drawable="@drawable/btn_default" />

styles.xml

    <style name="TextShadow">
    <item name="android:textColor">#ffffffff</item>
    <item name="android:shadowColor">#0D67B9</item>
    <item name="android:shadowRadius">2.0</item>
    <item name="android:shadowDy">-2.0</item>
</style>

<style name="BigButton" parent="TextShadow">
    <item name="android:background">@drawable/selector_btn</item>
</style>

解决方案

  You have make 2 defferent styles for enable and disable  condition and apply it to    textview when it disable or vise versa ...                     
            <style name="TextShadow_disable">
              <item name="android:textColor">#ffffffff</item>
               <item name="android:shadowColor">#0D67B9</item>
              <item name="android:shadowRadius">0</item>
             <item name="android:shadowDy">0</item>
              </style>
             <style name="TextShadow_enable">
              <item name="android:textColor">#ffffffff</item>
             <item name="android:shadowColor">#0D67B9</item>
             <item name="android:shadowRadius">2.0</item>
             <item name="android:shadowDy">-2.0</item>
            </style>

          textstyle = (TextView) findViewById(R.id.mytext);
          textstyle.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    getTextStyle();

                }
            });

write down this method to check enable disable;

     public void  getTextStyle()  {
           if(textstyle.isEnabled()){
                 textstyle.setTextAppearance(this, R.style.TextShadow_enable);
                }
             else{
                   textstyle.setTextAppearance(this, R.style.TextShadow_disable);
                }
          }   

这篇关于删除/添加动态阴影效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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