android setAlpha 与 getBackground().setAlpha
生活随笔
收集整理的這篇文章主要介紹了
android setAlpha 与 getBackground().setAlpha
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
setAlpha() 里面的取值為0f-1f 改變的是view的顏色以及view里面內容的顏色,
setAlpha(0f) 整個view 變為了透明?setAlpha(1f) 這個顯示原始的view?
getBackground().setAlpha() 里面的取值為 0-255 改變的背景顏色的變化
getBackground().setAlpha(0) 背景變為透明 ,getBackground().setAlpha(255)背景色 為默認的顏色
getBackground().setAlpha() 有時候使用的時候會改變其他控件的背景色也一起改變 這個時候需要
添加一個mutate 例如? getBackground().mutate().setAlpha(0); 這樣就不會影響到其他的布局了
寫幾個對比
寫幾個txtview 設置背景色如下
?
使用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);
效果圖下
可以看到第一個text 完全變為透明了
使用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);
效果圖如下
可以看的出只是改變了背景色,并沒有改變文字的顏色。。。。。
?
總結
以上是生活随笔為你收集整理的android setAlpha 与 getBackground().setAlpha的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: failed to load exter
- 下一篇: Android LayoutInflat