Android 透明TextView?
简单地说,如何使 TextView 透明?(不是完全透明)
我搜索了文档和 StackNetwork 但找不到它? 我想有这样的事情。
谢谢。
更新
这是XML代码:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:background="@drawable/background">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/header"
android:src="@drawable/logo1"
/>
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:paddingRight="5dp"
android:scrollbarStyle="outsideOverlay"
android:cacheColorHint="#00000000" />
<TextView
android:id="@+id/footer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:singleLine="true"
android:background="#07000000"
android:textColor="#FFFFFF"
android:text="rrrrr" />
</LinearLayout>
我希望页脚 TextView
是透明的以便在滚动时可以看到ListView项目< /代码>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(15)
请参阅 Android Color 资源文档以供参考。
基本上,您可以选择直接在布局中或使用资源引用设置透明度(不透明度)和颜色。
您设置的十六进制值由 3 到 4 个部分组成:
Alpha(不透明度),我将其称为 aa
绿色,我将其称为 gg
绿色,我将其称为 gg
蓝色,我将其称为 bb
不带 alpha(透明度)值:
或作为资源:
带 alpha(透明度)值:
或作为资源:
完全透明度的 alpha 值为00,无透明度的 alpha 值为透明度为FF。
请参阅下面的完整十六进制值:
您可以尝试使用这些值之间的值。
See the Android Color resource documentation for reference.
Basically you have the option to set the transparency (opacity) and the color either directly in the layout or using resources references.
The hex value that you set it to is composed of 3 to 4 parts:
Alpha (opacity), i'll refer to that as aa
Red, i'll refer to it as rr
Green, i'll refer to it as gg
Blue, i'll refer to it as bb
Without an alpha (transparency) value:
or as resource:
With an alpha (transparency) value:
or as resource:
The alpha value for full transparency is 00 and the alpha value for no transparency is FF.
See full range of hex values below:
You can experiment with values in between those.
下面的黑色代码:-
现在,如果我想使用不透明度,您可以使用下面的代码:-
以及下面的不透明度代码:-
十六进制不透明度值
refer 了解 Android 上的颜色(六个字符)
Below code for black:-
Now if i want to use opacity than you can use below code :-
and below for opacity code:-
Hex Opacity Values
refer Understanding colors on Android (six characters)
请尝试这段代码。
使用背景图像作为透明,因此可以解决这个问题。
或
或
请尝试以下...
Please try this piece of code..
Used background image as transparent so may be solved that.
OR
OR
Please try below ...
使用这个:
Use this:
例如,。
<TextView android:alpha="0.3" ...
, for example.以编程方式设置:
对我来说,我还必须在父布局上将其设置为 Color.TRANSPARENT。
To set programmatically:
For me, I also had to set it to Color.TRANSPARENT on the parent layout.
虽然这个答案很晚,但可能会帮助其他开发人员,所以我将其发布在这里。
上面的答案仅显示如何设置 TextView 的透明背景。我们可以通过两种方式实现透明的 Textview backcgorund:
第二种方法更好,因为它可以灵活地设置不同颜色的背景和 设置小部件的不透明度
然后使用 android:alpha="0.2"示例
Although this answer is very late but might help other developer so I'm posting it here.
Answers above showing only how to set transparent background of TextView. We can achieve transparent Textview backcgorund in two way:
Second approach is better because it gives flexibility to set background with different color and then setting setting opacity to widget using android:alpha="0.2"
Example
如果您正在寻找类似脉冲应用程序上图像上的文本视图的内容,请执行以下操作
If you are looking for something like the text view on the image on the pulse app do this
这个问题有很多答案,但只有少数是容易理解的。
总结一下并说清楚:
在 XML 中设置颜色透明的最佳解决方案是使用:
(作者:@darvinda)
使用Java代码设置它的最简单的解决方案将是:
(作者:@Aaron)
并解释什么是alpha 通道 (“颜色的透明度”)为:
00
(十六进制)以使任何颜色完全不透明ff
(十六进制)以使其透明(颜色不再重要)。因此,Alpha 通道表示 alpha-rgb 颜色空间 中的透明度。要使某些内容透明,您使用的 rgb 颜色并不重要,只要将“alpha”颜色设置为
00
即可。十六进制 中的值(十六进制)。 org/wiki/RGBA_color_model" rel="nofollow noreferrer">alpha-rgb 色彩空间 是:
“#aarrggbb”(a=alpha,r=红色,g=绿色 b=蓝色)
This question has many answers, but only a few are easy to understand.
Just to sum it up and make it clear:
The best solution to set a color transparent in XML would be to use:
(by @darvinda)
And easiest solution to set it with Java code would be:
(by @Aaron)
And to explain what the alpha channel ("the transparency of the color") is:
00
(hex) to make any color fully opaqueff
(hex) to make it transparent (the color doesn't matter anymore).So the alpha channel represents the degree of transparency in an alpha-rgb color space. To make something transparent it doesn't matter with rgb-color you use, as long as the "alpha"-color is set to
00
.The values (hex) in an alpha-rgb color space are:
"#aarrggbb" (a=alpha, r=red, g=green b=blue)
尝试在 TextView 中设置
android:background="#00000000"
。设置颜色 00 的 alpha 将使背景透明。我没有尝试过这个,但它应该有效。
Try setting
android:background="#00000000"
in TextView. Setting alpha of colour 00 will make the background transparent.I haven't tried this, but it should work.
每个人都正确地回答了透明度问题,但没有听取这个人对页脚后面滚动列表的需求。
您需要将页脚作为
ListView
的一部分。目前,列表不会向后滚动,因为 ListView 的布局不会在透明的页脚视图后面。创建一个RelativeLayout
并将透明度放置在底部。Everyone is answering correctly about the transparency but not listening to what the guy needs in regards to the list scrolling behind the footer.
You need to make the footer part of your
ListView
. At the moment the list won't scroll behind because the layout of the ListView does not go behind the footer view with the transparency. Make aRelativeLayout
and position the transparency at the bottom.万一有人想以编程方式做到这一点!
执行以下操作:
用此更新值文件夹中的颜色文件。
然后以编程方式调用透明度
In case someone wants to do this in the programming way!
Do the following:
Update the color file in your values folder with this.
then call the transparency programitically
尝试使用 android-studio 设计器在 Activity_main.xml 中设置透明度。
如果您希望它是透明的,请像这样编写白色:
白色:#FFFFFF,50% 透明度:#80FFFFFF
这是针对 Kotlin 的,不确定这对于基本的 android (java) 是否会以同样的方式工作。
try to set the transparency with the android-studio designer in activity_main.xml.
If you want it to be transparent, write it for example like this for white:
White: #FFFFFF, with 50% transparency: #80FFFFFF
This is for Kotlin tho, not sure if that will work the same way for basic android (java).
您好,请尝试使用以下颜色代码作为文本视图的背景。
android:background="#20535252"
Hi Please try with the below color code as textview's background.
android:background="#20535252"
最简单的方法
The simplest way