android– 按钮不透明度透明度

android– 按钮不透明度透明度,第1张

概述main.xml中:<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apkes/android"android:orientation="vertical"android:layout_width="fill_parent&

main.xml中:

<?xml version="1.0" enCoding="utf-8"?><linearLayout    xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:orIEntation="vertical"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"     androID:background="@drawable/background"        androID:gravity="center"        androID:color="#66FF0000"    >    <button        androID:ID="@+ID/button1"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:text="@string/noua"        androID:textStyle="bold"        androID:textcolor="#808080"         />    <button        androID:ID="@+ID/button2"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:text="@string/zece"        androID:textStyle="bold"        androID:textcolor="#808080" />    <button        androID:ID="@+ID/button3"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:text="@string/unspe"        androID:textStyle="bold"        androID:textcolor="#808080" />    <button        androID:ID="@+ID/button4"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:text="@string/doispe"        androID:textStyle="bold"        androID:textcolor="#808080"/></linearLayout>

这是我的main.xml,我试图使按钮最透明,但我仍然希望看到它们,我不知道要添加什么以及添加位置,请更正我的xml,底部的低不明度.有预谋的谢谢你:D

解决方法:

检查How to Set Opacity (Alpha) for View in Android

您可以设置对象背景的透明度,使用#XX808080,其中XX是Alpha /透明度值.

androID:background="#80FF0000"

这将是一个半透明的红色背景.

您可以使用textcolor属性以相同的方式设置按钮文本的透明度:

androID:textcolor="#80FF0000"

您还可以通过动画中的代码实现

AlphaAnimation AlphaAnim = new AlphaAnimation(1.0f, 0.5f);AlphaAnim.setDuration (400);mybutton.getBackground().startAnimation(AlphaAnim);  // set Alpha on background

或直接:

mybutton.getBackground().setAlpha(0.5f);   // added in API 11, sets Alpha on background

两种方法都将Alpha设置为50%

最后,您可以尝试为您的XML添加androID:Alpha:

<button        androID:ID="@+ID/button2"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:text="@string/zece"        androID:textStyle="bold"        androID:textcolor="#808080" androID:Alpha="0.5"/>
总结

以上是内存溢出为你收集整理的android – 按钮不透明度/透明度全部内容,希望文章能够帮你解决android – 按钮不透明度/透明度所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1120156.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存