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

本文是小编为大家收集整理的关于动态删除/添加阴影效果的处理方法,想解了动态删除/添加阴影效果的问题怎么解决?动态删除/添加阴影效果问题的解决办法?动态删除/添加阴影效果问题的解决方案?那么可以参考本文帮助大家快速定位并解决问题,译文如有不准确的地方,大家可以切到English参考源文内容。

问题描述

当我的按钮被禁用时,我需要删除文本阴影效果,当按钮启用时我需要再次添加此效果.

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();

                }
            });

写下这个方法来检查enable disable;

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

本文地址:https://www.itbaoku.cn/post/157491.html

问题描述

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);
                }
          }   
查看更多