android setAlpha 与 getBackground().setAlpha
setAlpha() 里面的取值為0f-1f 改變的是view的顏色以及view里面內(nèi)容的顏色,
setAlpha(0f) 整個(gè)view 變?yōu)榱送该?setAlpha(1f) 這個(gè)顯示原始的view?
getBackground().setAlpha() 里面的取值為 0-255 改變的背景顏色的變化
getBackground().setAlpha(0) 背景變?yōu)橥该?,getBackground().setAlpha(255)背景色 為默認(rèn)的顏色
getBackground().setAlpha() 有時(shí)候使用的時(shí)候會(huì)改變其他控件的背景色也一起改變 這個(gè)時(shí)候需要
添加一個(gè)mutate 例如? getBackground().mutate().setAlpha(0); 這樣就不會(huì)影響到其他的布局了
寫幾個(gè)對比
寫幾個(gè)txtview 設(shè)置背景色如下
?
使用setAlpha();
findViewById(R.id.txt).setAlpha(0f);
findViewById(R.id.txt1).setAlpha(0.3f);
findViewById(R.id.txt2).setAlpha(0.5f);
findViewById(R.id.txt3).setAlpha(0.8f);
findViewById(R.id.txt4).setAlpha(1f);
效果圖下
可以看到第一個(gè)text 完全變?yōu)橥该髁?/p>
使用getBackground().mutate().setAlpha(0)
findViewById(R.id.txt).getBackground().mutate().setAlpha(0);findViewById(R.id.txt1).getBackground().mutate().setAlpha(100);findViewById(R.id.txt2).getBackground().mutate().setAlpha(150);findViewById(R.id.txt3).getBackground().mutate().setAlpha(200);findViewById(R.id.txt4).getBackground().mutate().setAlpha(230);
效果圖如下
可以看的出只是改變了背景色,并沒有改變文字的顏色。。。。。
?
總結(jié)
以上是生活随笔為你收集整理的android setAlpha 与 getBackground().setAlpha的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: failed to load exter
- 下一篇: Android LayoutInflat