【问题标题】:Remove/add shadow effect dynamically动态删除/添加阴影效果
【发布时间】:2014-04-08 07:54:53
【问题描述】:

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

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>

【问题讨论】:

    标签: android text shadow


    【解决方案1】:
      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();
    
                    }
                });
    

    写下这个方法来检查启用禁用;

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

    【讨论】:

    • 非常感谢)它的工作原理)但是我实现了自己的按钮并覆盖了监听状态更改事件的 drawableStateChangedmethod()。并且每次状态改变时都会改变文本样式。
    猜你喜欢
    • 1970-01-01
    • 2015-01-09
    • 2015-03-08
    • 2012-06-06
    • 2015-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多