如何在Android上实现20%的透明度?

时间:2022-08-27 12:16:32

How do I make the background of a Textview about 20% transparent (not fully transparent), where there is a color in the background (i.e. white)?

如何将文本视图的背景设置为20%透明(不是完全透明),而背景中有颜色(例如白色)?

13 个解决方案

#1


875  

Make the color have 80% in the alpha channel. For example, for red use #CCFF0000:

使颜色在alpha通道中有80%。例如,红色使用#CCFF0000:

<TextView
   ...
   android:background="#CCFF0000" />

In the example, CC is the hexadecimal number for 255 * 0.8 = 204. Note that the first two hexadecimal digits are for the alpha channel. The format is #AARRGGBB, where AA is the alpha channel, RR is the red channel, GG is the green channel and BB is the blue channel.

在本例中,CC是255 * 0.8 = 204的十六进制数字。注意,前两个十六进制数字是阿尔法通道的数字。格式是#AARRGGBB, AA是alpha通道,RR是红色通道,GG是绿色通道,BB是蓝色通道。

I'm assuming that 20% transparent means 80% opaque. If you meant the other way, instead of CC use 33 which is the hexadecimal for 255 * 0.2 = 51.

我假设20%透明度意味着80%不透明。如果你的意思是相反的,用33代替CC, 33是16进制的255 * 0。2 = 51。

In order to calculate the proper value for an alpha transparency value you can follow this procedure:

为了计算alpha透明度值的适当值,您可以遵循以下步骤:

  1. Given a transparency percentage, for example 20%, you know the opaque percentage value is 80% (this is 100-20=80)
  2. 给定一个透明度百分比,例如20%不透明百分比值是80% (100-20=80)
  3. The range for the alpha channel is 8 bits (2^8=256), meaning the range goes from 0 to 255.
  4. alpha通道的范围是8位(2 ^ 8 = 256),这意味着从0到255之间。
  5. Project the opaque percentage into the alpha range, that is, multiply the range (255) by the percentage. In this example 255 * 0.8 = 204. Round to the nearest integer if needed.
  6. 将不透明的百分比投射到alpha范围中,即将范围(255)乘以百分比。在本例中,255 * 0.8 = 204。如果需要,四舍五入到最近的整数。
  7. Convert the value obtained in 3., which is in base 10, to hexadecimal (base 16). You can use Google for this or any calculator. Using Google, type "204 to hexa" and it will give you the hexadecimal value. In this case it is 0xCC.
  8. 转换在3中获得的值。,以10为基数,以16为基数。你可以用谷歌来做这个或任何计算器。使用谷歌,输入“204到十六进制”,它会给你十六进制值。在这种情况下,它是0xCC。
  9. Prepend the value obtained in 4. to the desired color. For example, for red, which is FF0000, you will have CCFF0000.
  10. 在4中求值之前。所需的颜色。例如,对于red,也就是FF0000,您将拥有CCFF0000。

You can take a look at the Android documentation for colors.

您可以查看Android文档中的颜色。

#2


1222  

Use the below code for black:

使用以下代码为黑色:

<color name="black">#000000</color>

Now if I want to use opacity then you can use the below code:

现在,如果我想使用不透明度,你可以使用下面的代码:

 <color name="black">#99000000</color> 

And below for opacity code:

下面是不透明代码:

Hex Opacity Values

100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
60% — 99
55% — 8C
50% — 80
45% — 73
40% — 66
35% — 59
30% — 4D
25% — 40
20% — 33
15% — 26
10% — 1A
5% — 0D
0% — 00

If you always to forget what code for transparency then you must have to see below link and no worry about to remember anything regarding transparent code :-

如果你总是忘记透明的代码,那么你必须看到下面的链接,不用担心记住任何关于透明代码的东西:-

https://github.com/duggu-hcd/TransparentColorCode

https://github.com/duggu-hcd/TransparentColorCode

textviewHeader.setTextColor(Color.parseColor(ColorTransparentUtils.transparentColor10(R.color.border_color)));

#3


95  

You can manage color opacity changing the first 2 characters in the color definition:

您可以管理颜色不透明度,更改颜色定义的前两个字符:

#99000000

# 99000000

100% — FF
99% — FC
98% — FA
97% — F7
96% — F5
95% — F2
94% — F0
93% — ED
92% — EB
91% — E8

90% — E6
89% — E3
88% — E0
87% — DE
86% — DB
85% — D9
84% — D6
83% — D4
82% — D1
81% — CF

80% — CC
79% — C9
78% — C7
77% — C4
76% — C2
75% — BF
74% — BD
73% — BA
72% — B8
71% — B5

70% — B3
69% — B0
68% — AD
67% — AB
66% — A8
65% — A6
64% — A3
63% — A1
62% — 9E
61% — 9C

60% — 99
59% — 96
58% — 94
57% — 91
56% — 8F
55% — 8C
54% — 8A
53% — 87
52% — 85
51% — 82

50% — 80
49% — 7D
48% — 7A
47% — 78
46% — 75
45% — 73
44% — 70
43% — 6E
42% — 6B
41% — 69

40% — 66
39% — 63
38% — 61
37% — 5E
36% — 5C
35% — 59
34% — 57
33% — 54
32% — 52
31% — 4F

30% — 4D
29% — 4A
28% — 47
27% — 45
26% — 42
25% — 40
24% — 3D
23% — 3B
22% — 38
21% — 36

20% — 33
19% — 30
18% — 2E
17% — 2B
16% — 29
15% — 26
14% — 24
13% — 21
12% — 1F
11% — 1C

10% — 1A
9% — 17
8% — 14
7% — 12
6% — 0F
5% — 0D
4% — 0A
3% — 08
2% — 05
1% — 03
0% — 00 

#4


90  

Use a color with an alpha value like #33------, and set it as background of your editText using the XML attribute android:background=" ".

使用带有alpha值的颜色,如#33----,并使用XML属性android:background=" "将其设置为editText的背景。

  1. 0% (transparent) -> #00 in hex
  2. 0%(透明)-> #00在十六进制
  3. 20% -> #33
  4. - > # 33 20%
  5. 50% -> #80
  6. 50% - > # 80
  7. 75% -> #C0
  8. # C0 - > 75%
  9. 100% (opaque) -> #FF
  10. 100%(不透明)- > # FF

255 * 0.2 = 51 → in hex 33

255 * 0.2 = 51→十六进制33

#5


71  

You can try to do something like:

你可以这样做:

textView.getBackground().setAlpha(51);

Here you can set the opacity between 0 (fully transparent) to 255 (completely opaque). The 51 is exactly the 20% you want.

这里可以将不透明度设置为0(完全透明)到255(完全不透明)。51正好是你想要的20%

#6


52  

In Android Studio there is a built-in tool to adjust the color and alpha/opacity value:

在Android Studio中有一个内置的工具来调整颜色和alpha/不透明度值:

如何在Android上实现20%的透明度?

#7


21  

如何在Android上实现20%的透明度?

I have taken three Views. In the first view I set full (no alpha) color, on the second view I set half (0.5 alpha) color, and on the third view I set light color (0.2 alpha).

我有三个观点。在第一个视图中,我设置了full(无alpha)颜色,在第二个视图中,我设置了half (0.5 alpha)颜色,在第三个视图中,我设置了light颜色(0.2 alpha)。

You can set any color and get color with alpha by using the below code:

您可以通过以下代码设置任何颜色并使用alpha获得颜色:

File activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools = "http://schemas.android.com/tools"
    android:layout_width = "match_parent"
    android:layout_height = "match_parent"
    android:gravity = "center"
    android:orientation = "vertical"
    tools:context = "com.example.temp.MainActivity" >

    <View
        android:id = "@+id/fullColorView"
        android:layout_width = "100dip"
        android:layout_height = "100dip" />

    <View
        android:id = "@+id/halfalphaColorView"
        android:layout_width = "100dip"
        android:layout_height = "100dip"
        android:layout_marginTop = "20dip" />

    <View
        android:id = "@+id/alphaColorView"
        android:layout_width = "100dip"
        android:layout_height = "100dip"
        android:layout_marginTop = "20dip" />

</LinearLayout>

File MainActivity.java

public class MainActivity extends Activity {

    private View fullColorView, halfalphaColorView, alphaColorView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        fullColorView = (View)findViewById(R.id.fullColorView);
        halfalphaColorView = (View)findViewById(R.id.halfalphaColorView);
        alphaColorView = (View)findViewById(R.id.alphaColorView);

        fullColorView.setBackgroundColor(Color.BLUE);
        halfalphaColorView.setBackgroundColor(getColorWithAlpha(Color.BLUE, 0.5f));
        alphaColorView.setBackgroundColor(getColorWithAlpha(Color.BLUE, 0.2f));
    }


    public static int getColorWithAlpha(int color, float ratio) {
        int newColor = 0;
        int alpha = Math.round(Color.alpha(color) * ratio);
        int r = Color.red(color);
        int g = Color.green(color);
        int b = Color.blue(color);
        newColor = Color.argb(alpha, r, g, b);
        return newColor;
    }
}

Done

完成

#8


15  

There is an XML value alpha that takes double values.

有一个具有双重值的XML值。

Since API 11+ the range is from 0f to 1f (inclusive), 0f being transparent and 1f being opaque:

由于API 11+范围从0f到1f(含),0f为透明,1f为不透明:

  • android:alpha="0.0" thats invisible

    android:α= " 0.0 "这是无形的

  • android:alpha="0.5" see-through

    android:α= " 0.5 "透明

  • android:alpha="1.0" full visible

    android:α= " 1.0 "完全可见

That's how it works.

这是它是如何工作的。

#9


5  

<TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:alpha="0.9"
        />

Alpha ranges between 0(transparent) and 1(opaque) in Android API 11+

Alpha值在0(透明)和1(不透明)之间

#10


4  

All hex value from 100% to 0% alpha, You can set any color with alpha values mentioned below. e.g #FAFFFFFF(ARRGGBB)

所有十六进制值从100%到0%,你可以设置任何颜色的alpha值如下所示。e。g # FAFFFFFF(ARRGGBB)

100% — FF
99% — FC
98% — FA
97% — F7
96% — F5
95% — F2
94% — F0
93% — ED
92% — EB
91% — E8
90% — E6
89% — E3
88% — E0
87% — DE
86% — DB
85% — D9
84% — D6
83% — D4
82% — D1
81% — CF
80% — CC
79% — C9
78% — C7
77% — C4
76% — C2
75% — BF
74% — BD
73% — BA
72% — B8
71% — B5
70% — B3
69% — B0
68% — AD
67% — AB
66% — A8
65% — A6
64% — A3
63% — A1
62% — 9E
61% — 9C
60% — 99
59% — 96
58% — 94
57% — 91
56% — 8F
55% — 8C
54% — 8A
53% — 87
52% — 85
51% — 82
50% — 80
49% — 7D
48% — 7A
47% — 78
46% — 75
45% — 73
44% — 70
43% — 6E
42% — 6B
41% — 69
40% — 66
39% — 63
38% — 61
37% — 5E
36% — 5C
35% — 59
34% — 57
33% — 54
32% — 52
31% — 4F
30% — 4D
29% — 4A
28% — 47
27% — 45
26% — 42
25% — 40
24% — 3D
23% — 3B
22% — 38
21% — 36
20% — 33
19% — 30
18% — 2E
17% — 2B
16% — 29
15% — 26
14% — 24
13% — 21
12% — 1F
11% — 1C
10% — 1A
9% — 17
8% — 14
7% — 12
6% — 0F
5% — 0D
4% — 0A
3% — 08
2% — 05
1% — 03
0% — 00

#11


1  

See Popularity below textView using this

请参见textView下面的流行度

     android:alpha="0.38"

如何在Android上实现20%的透明度?

XML

XML

android:color="#3983BE00"    // Partially transparent sky blue

Dynamically

动态

btn.getBackground().setAlpha(128); // 50% transparent

btn.getBackground().setAlpha(128);/ / 50%透明

tv_name.getBackground().setAlpha(128); // 50% transparent

tv_name.getBackground().setAlpha(128);/ / 50%透明

Where the INT ranges from 0 (fully transparent) to 255 (fully opaque).


  <TextView
            style="@style/TextAppearance.AppCompat.Caption"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:alpha="0.38"
            android:gravity="start"
            android:textStyle="bold"
            tools:text="1994|EN" />

android:alpha="0.38"

android:α= " 0.38 "

Text View alpha property set 0.38 to your textView visibility is faid 

#12


0  

Here's a programmatic solution from @Aromero's answer to calculate the hexadecimal value for the alpha channel. :)

下面是@Aromero的一个编程解决方案,用于计算alpha通道的十六进制值。:)

 public static void main(String[] args) throws Exception {
    final Scanner scanner = new Scanner(System.in);
    int transPerc;
    float fPerc;
    System.out.println("Enter the transparency percentage without % symbol:");
    while((transPerc=scanner.nextInt())>=0 && transPerc <=100){
        fPerc = (float) transPerc / 100;
        transPerc = Math.round(255 * fPerc);
        System.out.println("= " + Integer.toHexString(transPerc));
        System.out.print("another one please : ");
    }
    scanner.close();
}

#13


0  

Try this code :)

试试这个代码:)

Its an fully transparent hex code - "#00000000"

它是一个完全透明的十六进制编码——“#00000000”

#1


875  

Make the color have 80% in the alpha channel. For example, for red use #CCFF0000:

使颜色在alpha通道中有80%。例如,红色使用#CCFF0000:

<TextView
   ...
   android:background="#CCFF0000" />

In the example, CC is the hexadecimal number for 255 * 0.8 = 204. Note that the first two hexadecimal digits are for the alpha channel. The format is #AARRGGBB, where AA is the alpha channel, RR is the red channel, GG is the green channel and BB is the blue channel.

在本例中,CC是255 * 0.8 = 204的十六进制数字。注意,前两个十六进制数字是阿尔法通道的数字。格式是#AARRGGBB, AA是alpha通道,RR是红色通道,GG是绿色通道,BB是蓝色通道。

I'm assuming that 20% transparent means 80% opaque. If you meant the other way, instead of CC use 33 which is the hexadecimal for 255 * 0.2 = 51.

我假设20%透明度意味着80%不透明。如果你的意思是相反的,用33代替CC, 33是16进制的255 * 0。2 = 51。

In order to calculate the proper value for an alpha transparency value you can follow this procedure:

为了计算alpha透明度值的适当值,您可以遵循以下步骤:

  1. Given a transparency percentage, for example 20%, you know the opaque percentage value is 80% (this is 100-20=80)
  2. 给定一个透明度百分比,例如20%不透明百分比值是80% (100-20=80)
  3. The range for the alpha channel is 8 bits (2^8=256), meaning the range goes from 0 to 255.
  4. alpha通道的范围是8位(2 ^ 8 = 256),这意味着从0到255之间。
  5. Project the opaque percentage into the alpha range, that is, multiply the range (255) by the percentage. In this example 255 * 0.8 = 204. Round to the nearest integer if needed.
  6. 将不透明的百分比投射到alpha范围中,即将范围(255)乘以百分比。在本例中,255 * 0.8 = 204。如果需要,四舍五入到最近的整数。
  7. Convert the value obtained in 3., which is in base 10, to hexadecimal (base 16). You can use Google for this or any calculator. Using Google, type "204 to hexa" and it will give you the hexadecimal value. In this case it is 0xCC.
  8. 转换在3中获得的值。,以10为基数,以16为基数。你可以用谷歌来做这个或任何计算器。使用谷歌,输入“204到十六进制”,它会给你十六进制值。在这种情况下,它是0xCC。
  9. Prepend the value obtained in 4. to the desired color. For example, for red, which is FF0000, you will have CCFF0000.
  10. 在4中求值之前。所需的颜色。例如,对于red,也就是FF0000,您将拥有CCFF0000。

You can take a look at the Android documentation for colors.

您可以查看Android文档中的颜色。

#2


1222  

Use the below code for black:

使用以下代码为黑色:

<color name="black">#000000</color>

Now if I want to use opacity then you can use the below code:

现在,如果我想使用不透明度,你可以使用下面的代码:

 <color name="black">#99000000</color> 

And below for opacity code:

下面是不透明代码:

Hex Opacity Values

100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
60% — 99
55% — 8C
50% — 80
45% — 73
40% — 66
35% — 59
30% — 4D
25% — 40
20% — 33
15% — 26
10% — 1A
5% — 0D
0% — 00

If you always to forget what code for transparency then you must have to see below link and no worry about to remember anything regarding transparent code :-

如果你总是忘记透明的代码,那么你必须看到下面的链接,不用担心记住任何关于透明代码的东西:-

https://github.com/duggu-hcd/TransparentColorCode

https://github.com/duggu-hcd/TransparentColorCode

textviewHeader.setTextColor(Color.parseColor(ColorTransparentUtils.transparentColor10(R.color.border_color)));

#3


95  

You can manage color opacity changing the first 2 characters in the color definition:

您可以管理颜色不透明度,更改颜色定义的前两个字符:

#99000000

# 99000000

100% — FF
99% — FC
98% — FA
97% — F7
96% — F5
95% — F2
94% — F0
93% — ED
92% — EB
91% — E8

90% — E6
89% — E3
88% — E0
87% — DE
86% — DB
85% — D9
84% — D6
83% — D4
82% — D1
81% — CF

80% — CC
79% — C9
78% — C7
77% — C4
76% — C2
75% — BF
74% — BD
73% — BA
72% — B8
71% — B5

70% — B3
69% — B0
68% — AD
67% — AB
66% — A8
65% — A6
64% — A3
63% — A1
62% — 9E
61% — 9C

60% — 99
59% — 96
58% — 94
57% — 91
56% — 8F
55% — 8C
54% — 8A
53% — 87
52% — 85
51% — 82

50% — 80
49% — 7D
48% — 7A
47% — 78
46% — 75
45% — 73
44% — 70
43% — 6E
42% — 6B
41% — 69

40% — 66
39% — 63
38% — 61
37% — 5E
36% — 5C
35% — 59
34% — 57
33% — 54
32% — 52
31% — 4F

30% — 4D
29% — 4A
28% — 47
27% — 45
26% — 42
25% — 40
24% — 3D
23% — 3B
22% — 38
21% — 36

20% — 33
19% — 30
18% — 2E
17% — 2B
16% — 29
15% — 26
14% — 24
13% — 21
12% — 1F
11% — 1C

10% — 1A
9% — 17
8% — 14
7% — 12
6% — 0F
5% — 0D
4% — 0A
3% — 08
2% — 05
1% — 03
0% — 00 

#4


90  

Use a color with an alpha value like #33------, and set it as background of your editText using the XML attribute android:background=" ".

使用带有alpha值的颜色,如#33----,并使用XML属性android:background=" "将其设置为editText的背景。

  1. 0% (transparent) -> #00 in hex
  2. 0%(透明)-> #00在十六进制
  3. 20% -> #33
  4. - > # 33 20%
  5. 50% -> #80
  6. 50% - > # 80
  7. 75% -> #C0
  8. # C0 - > 75%
  9. 100% (opaque) -> #FF
  10. 100%(不透明)- > # FF

255 * 0.2 = 51 → in hex 33

255 * 0.2 = 51→十六进制33

#5


71  

You can try to do something like:

你可以这样做:

textView.getBackground().setAlpha(51);

Here you can set the opacity between 0 (fully transparent) to 255 (completely opaque). The 51 is exactly the 20% you want.

这里可以将不透明度设置为0(完全透明)到255(完全不透明)。51正好是你想要的20%

#6


52  

In Android Studio there is a built-in tool to adjust the color and alpha/opacity value:

在Android Studio中有一个内置的工具来调整颜色和alpha/不透明度值:

如何在Android上实现20%的透明度?

#7


21  

如何在Android上实现20%的透明度?

I have taken three Views. In the first view I set full (no alpha) color, on the second view I set half (0.5 alpha) color, and on the third view I set light color (0.2 alpha).

我有三个观点。在第一个视图中,我设置了full(无alpha)颜色,在第二个视图中,我设置了half (0.5 alpha)颜色,在第三个视图中,我设置了light颜色(0.2 alpha)。

You can set any color and get color with alpha by using the below code:

您可以通过以下代码设置任何颜色并使用alpha获得颜色:

File activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools = "http://schemas.android.com/tools"
    android:layout_width = "match_parent"
    android:layout_height = "match_parent"
    android:gravity = "center"
    android:orientation = "vertical"
    tools:context = "com.example.temp.MainActivity" >

    <View
        android:id = "@+id/fullColorView"
        android:layout_width = "100dip"
        android:layout_height = "100dip" />

    <View
        android:id = "@+id/halfalphaColorView"
        android:layout_width = "100dip"
        android:layout_height = "100dip"
        android:layout_marginTop = "20dip" />

    <View
        android:id = "@+id/alphaColorView"
        android:layout_width = "100dip"
        android:layout_height = "100dip"
        android:layout_marginTop = "20dip" />

</LinearLayout>

File MainActivity.java

public class MainActivity extends Activity {

    private View fullColorView, halfalphaColorView, alphaColorView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        fullColorView = (View)findViewById(R.id.fullColorView);
        halfalphaColorView = (View)findViewById(R.id.halfalphaColorView);
        alphaColorView = (View)findViewById(R.id.alphaColorView);

        fullColorView.setBackgroundColor(Color.BLUE);
        halfalphaColorView.setBackgroundColor(getColorWithAlpha(Color.BLUE, 0.5f));
        alphaColorView.setBackgroundColor(getColorWithAlpha(Color.BLUE, 0.2f));
    }


    public static int getColorWithAlpha(int color, float ratio) {
        int newColor = 0;
        int alpha = Math.round(Color.alpha(color) * ratio);
        int r = Color.red(color);
        int g = Color.green(color);
        int b = Color.blue(color);
        newColor = Color.argb(alpha, r, g, b);
        return newColor;
    }
}

Done

完成

#8


15  

There is an XML value alpha that takes double values.

有一个具有双重值的XML值。

Since API 11+ the range is from 0f to 1f (inclusive), 0f being transparent and 1f being opaque:

由于API 11+范围从0f到1f(含),0f为透明,1f为不透明:

  • android:alpha="0.0" thats invisible

    android:α= " 0.0 "这是无形的

  • android:alpha="0.5" see-through

    android:α= " 0.5 "透明

  • android:alpha="1.0" full visible

    android:α= " 1.0 "完全可见

That's how it works.

这是它是如何工作的。

#9


5  

<TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:alpha="0.9"
        />

Alpha ranges between 0(transparent) and 1(opaque) in Android API 11+

Alpha值在0(透明)和1(不透明)之间

#10


4  

All hex value from 100% to 0% alpha, You can set any color with alpha values mentioned below. e.g #FAFFFFFF(ARRGGBB)

所有十六进制值从100%到0%,你可以设置任何颜色的alpha值如下所示。e。g # FAFFFFFF(ARRGGBB)

100% — FF
99% — FC
98% — FA
97% — F7
96% — F5
95% — F2
94% — F0
93% — ED
92% — EB
91% — E8
90% — E6
89% — E3
88% — E0
87% — DE
86% — DB
85% — D9
84% — D6
83% — D4
82% — D1
81% — CF
80% — CC
79% — C9
78% — C7
77% — C4
76% — C2
75% — BF
74% — BD
73% — BA
72% — B8
71% — B5
70% — B3
69% — B0
68% — AD
67% — AB
66% — A8
65% — A6
64% — A3
63% — A1
62% — 9E
61% — 9C
60% — 99
59% — 96
58% — 94
57% — 91
56% — 8F
55% — 8C
54% — 8A
53% — 87
52% — 85
51% — 82
50% — 80
49% — 7D
48% — 7A
47% — 78
46% — 75
45% — 73
44% — 70
43% — 6E
42% — 6B
41% — 69
40% — 66
39% — 63
38% — 61
37% — 5E
36% — 5C
35% — 59
34% — 57
33% — 54
32% — 52
31% — 4F
30% — 4D
29% — 4A
28% — 47
27% — 45
26% — 42
25% — 40
24% — 3D
23% — 3B
22% — 38
21% — 36
20% — 33
19% — 30
18% — 2E
17% — 2B
16% — 29
15% — 26
14% — 24
13% — 21
12% — 1F
11% — 1C
10% — 1A
9% — 17
8% — 14
7% — 12
6% — 0F
5% — 0D
4% — 0A
3% — 08
2% — 05
1% — 03
0% — 00

#11


1  

See Popularity below textView using this

请参见textView下面的流行度

     android:alpha="0.38"

如何在Android上实现20%的透明度?

XML

XML

android:color="#3983BE00"    // Partially transparent sky blue

Dynamically

动态

btn.getBackground().setAlpha(128); // 50% transparent

btn.getBackground().setAlpha(128);/ / 50%透明

tv_name.getBackground().setAlpha(128); // 50% transparent

tv_name.getBackground().setAlpha(128);/ / 50%透明

Where the INT ranges from 0 (fully transparent) to 255 (fully opaque).


  <TextView
            style="@style/TextAppearance.AppCompat.Caption"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:alpha="0.38"
            android:gravity="start"
            android:textStyle="bold"
            tools:text="1994|EN" />

android:alpha="0.38"

android:α= " 0.38 "

Text View alpha property set 0.38 to your textView visibility is faid 

#12


0  

Here's a programmatic solution from @Aromero's answer to calculate the hexadecimal value for the alpha channel. :)

下面是@Aromero的一个编程解决方案,用于计算alpha通道的十六进制值。:)

 public static void main(String[] args) throws Exception {
    final Scanner scanner = new Scanner(System.in);
    int transPerc;
    float fPerc;
    System.out.println("Enter the transparency percentage without % symbol:");
    while((transPerc=scanner.nextInt())>=0 && transPerc <=100){
        fPerc = (float) transPerc / 100;
        transPerc = Math.round(255 * fPerc);
        System.out.println("= " + Integer.toHexString(transPerc));
        System.out.print("another one please : ");
    }
    scanner.close();
}

#13


0  

Try this code :)

试试这个代码:)

Its an fully transparent hex code - "#00000000"

它是一个完全透明的十六进制编码——“#00000000”