当前位置:首页 » 安卓系统 » android设置颜色透明

android设置颜色透明

发布时间: 2022-06-13 03:02:32

❶ android中怎样把背景透明

实现方式一(使用系统透明样式)
通过配置 Activity 的样式来实现,在 AndroidManifest.xml 找到要实现透明效果的 Activity,在 Activity 的配置中添加如下的代码设置该 Activity 为透明样式,但这种实现方式只能实现纯透明的样式,无法调整透明度,所以这种实现方式有一定的局限性,但这种方式实现简单。
android:theme="@android:style/Theme.Translucent"

<activity
android:name="cn.sunzn.transact.MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

实现方式二(使用自定义透明样式)
这种方式的实现同样要配置 Activity 的样式,只不过这里的样式是我们自定义的。具体实现过程如下:
1 在 res/values/color.xml 文件下加入一个透明颜色值,这里的 color 参数,是两位数一个单位,前两位数是透明度,后面每两位一对是16进制颜色数字,示例中为白色。
<?xml version="1.0" encoding="utf-8"?>
<resources>

<color name="translucent_background">#80000000</color>

</resources>

2 在 res/values/styles.xml 文件中加入一个自定义样式,代码如下。

<!-- item name="android:windowBackground" 设置背景透明度及其颜色值 -->
<!-- item name="android:windowIsTranslucent" 设置当前Activity是否透明-->
<!-- item name="android:windowAnimationStyle" 设置当前Activity进出方式-->
<style name="translucent">
<item name="android:windowBackground">@color/translucent_background</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item>
</style>

3 在 AndroidManifest.xml 找到要实现透明的 Activity,在想要实现透明的 Activity 中配置其属性,代码如下;也可在该 Activity 的 onCreat() 方法中调用 setTheme(R.style.translucent) 来实现。

<activity
android:name="cn.sunzn.transact.MainActivity"
android:label="@string/app_name"
android:theme="@style/translucent" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

❷ android Button 怎么把背景设置透明

Android控件设置边框,或者背景可以使用XML来配置,背景透明只需要设置solid 的值为 #00000000即可,前面两位是透明度,后面6位是RGB颜色值,具体示例代码如下:
1.在drawable新建一个 buttonstyle.xml的文件,内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 连框颜色值 --><item>
<shape>
<solid android:color="#ff0000" />
</shape>
</item>
<!-- 主体背景颜色值 -->
<item android:bottom="3dp" android:right="3dp">
<shape>
<solid android:color="#ffffff" />
<padding android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
</shape>
</item>
</layer-list>

2.然后在布局文件里面引入这个xml,示例代码如下:
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1"
android:background="@drawable/buttonstyle" />

❸ 请教android怎么让控件背景透明

以Android Studio为例,步骤如下:

1、直接打开相关窗口,在Android-app-res-layout的空白处点击鼠标右键并选择New-Layoutresource file。

❹ android 如何把一个 RelativeLayout或ImageView背景设为透明

设置背景为透明
1、设置背景为透明
<ImageView
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:background="@android:color/transparent"/><!--#00000000-->也可以设置颜色值,前两位为透明度
2、设置背景透明度
<ImageView
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0"/>
相应的也可以在java代码中设置透明

❺ android 为什么背景设置为透明

方法一: 只要在配置文件内activity属性配置内加上 android:theme="@android:style/Theme.Translucent" 就好了。 这样就调用了android的透明样式! 方法二: 先在res/values下建colors.xml文件,写入: <?xmlversionxmlversion="1.0"encoding="UTF-8"?> <resources> <colornamecolorname="transparent">#9000</color> </resources> 这个值设定了整个界面的透明度,为了看得见效果,现在设为透明度为56%(9/16)左右。

❻ android编程如何把现有的背景图片设置成透明的

方法一:
只要在配置文件内activity属性配置内加上

android:theme="@android:style/Theme.Translucent"

就好了。

这样就调用了android的透明样式!
方法二:
先在res/values下建colors.xml文件,写入:
<?xmlversionxmlversion="1.0"encoding="UTF-8"?>

<resources>

<colornamecolorname="transparent">#9000</color>

</resources>
这个值设定了整个界面的透明度,为了看得见效果,现在设为透明度为56%(9/16)左右。

❼ android中怎么设置color为透明颜色或者半透明颜色

正常设置颜色是“#”后面加6位16进制数字,在这6位前面再加两位就是用来设置透明度的。

❽ android studio activity怎么设置透明背景

Android studio在Manifest.xml中找到对应的activity在里面加上android:theme="@android:style/Theme.Translucent"即可背景透明,如果还想取消标题栏和全屏的画可以将style/改为Theme.Translucent.NoTitleBar.Fullscreen

❾ android怎么动态设置透明度

工具

eclipse

方法

  1. #ff000000 此为16进制颜色代码,前2位ff为透明度,后6位为颜色值

  2. 透明度分为256阶(0-255),计算机上用16进制表示为(00-ff)

  3. 10进制的255换算成16进制是ff,127换算成16进制是7f

  4. 适用脚本

热点内容
内置存储卡可以拆吗 发布:2025-05-18 04:16:35 浏览:333
编译原理课时设置 发布:2025-05-18 04:13:28 浏览:374
linux中进入ip地址服务器 发布:2025-05-18 04:11:21 浏览:610
java用什么软件写 发布:2025-05-18 03:56:19 浏览:31
linux配置vim编译c 发布:2025-05-18 03:55:07 浏览:107
砸百鬼脚本 发布:2025-05-18 03:53:34 浏览:940
安卓手机如何拍视频和苹果一样 发布:2025-05-18 03:40:47 浏览:738
为什么安卓手机连不上苹果7热点 发布:2025-05-18 03:40:13 浏览:802
网卡访问 发布:2025-05-18 03:35:04 浏览:510
接收和发送服务器地址 发布:2025-05-18 03:33:48 浏览:371