* preface
Some requirements will change the layout color transparency , For example, according to the sliding distance , change title colour , Set controls such as View,Button Transparency of , Yes 3 Methods .

<>2. usage method

(1)java code implementation :
text = (TextView) findViewById(R.id.text); text.getBackground().setAlpha(12);
setAlpha() Can be filled in brackets of 0–255 Number between . The bigger the number , More opaque .

Attention points : stay 5.0 For the above systems , Some models will have inexplicable color values that don't work , Become transparent , That is to say, using this method will lead to the layout of other shared resources ( for example :@color/white) Transparency also changes .
such as text After setting transparent with the above method , In the project , Other uses text Controls for color values , It's all transparent .

reason : When multiple controls in a layout use a resource at the same time , These controls share a state , for example ColorState, If you change the state of a control , Other controls receive the same notifications . Now we can use mutate() Method to make the control state indeterminate , In this way, the control with indefinite state will not share its own state .
(2) stay xml Setting in layout
<TextView android:id="@+id/text" android:text="Hello World!"
android:background="#987654" android:layout_width="match_parent"
android:alpha="0.5" android:layout_height="100dp" />
android:alpha The value of is 0~1 Number between . The bigger the number , More opaque .1 Indicates full opacity ,0 Indicates full transparency .

(3) stay xml Pass in layout android:background set up
<TextView android:id="@+id/text" android:text="Hello World!"
android:background="#80987654" android:layout_width="match_parent"
android:layout_height="100dp" />
Color and opacity (alpha) Values are represented in hexadecimal notation . The value range of any color is 0 reach 255(00 reach ff). about alpha,00
Indicates full transparency ,ff
Indicates full opacity .android:background The format of the value of is "#AARRGGBB".AA Transparency ,R,G,B It's red, green and blue . Each is 0–F 16 digits of . The greater the value of transparency , More opaque . So if you want to set the transparency to 50% In white , Can be set as above .

Please point out any mistakes , Learning together .

©2019-2020 Toolsou All rights reserved,
One and a half years JAVA Summary of work experience Jsp+Ajax+Servlet+Mysql Add, delete, modify and query ( one ) cartoon | CPU Warfare 40 year , The real king finally appeared ! Don't annoy the panda with any cat !「 Kung Fu Panda 」20 It's the year of man 4 blood IAR Installation and use tutorial Classical algorithm - recursion ( The case of raw rabbit ) Thorough explanation from Zhongtai Random forest R Language implementation R Language cluster analysis case These songs , Programmers, don't listen !