当前位置:首页 » 安卓系统 » android布局透明度

android布局透明度

发布时间: 2023-02-23 08:25:23

A. 如何设置Android中控件的颜色透明度

设置Android中控件的颜色透明度需要设置设置控件的background属性设置方法如下。

1、使用Android studio创建一个Android 项目,如下图:

B. 如何设置Android中控件的颜色透明度

Android中设置ImageView控件的图片的透明度应该调用View的api,以下为示例:
1、用android系统的透明效果
Java代码
android:background="@android:color/transparent"
例如
设置按钮
Java代码
<Button
android:background="@android:color/transparent"
android:text="@+id/Button01"
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
/>
2、用ARGB来控制
Java代码
半透明<Button
android:background="#e0000000"
/>
透明<Button
android:background="#00000000"
/>
3、设置alpha
Java代码
View
v
=
findViewById(R.id.content);
v.getBackground().setAlpha(100);
说明:
0~255透明度值,0表示完全不透明,255表示完全透明。

C. 怎样将android控件背景设置成透明

1、打开安卓的配置文件。

2、只需要在配置文件中把需要设置为透明的activity的样式设置为android:theme="@android:style/Theme.Translucent"

3、这样就可以把背景设置为透明。

D. android 怎么设置线性布局 帧布局 全透明

Android设置线性布局 帧布局 全透明如下

1、LinearLayout(线性布局)
[html] view plainprint?
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/mobile" />

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:id="@+id/mobile" />

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/button"

android:id="@+id/button"/>

<CheckBox

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

</LinearLayout>

2、RelativeLayout(相对布局)

[html] view plainprint?
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

<RelativeLayout

android:layout_width="fill_parent"

android:layout_height="wrap_content">

<TextView

android:layout_width="100dp"

android:layout_height="wrap_content"

android:text="@string/number"

android:id="@+id/numberlabel" />

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:id="@+id/number"

android:layout_toRightOf="@id/numberlabel"

android:layout_alignTop="@id/numberlabel"

android:layout_marginLeft="5dp"/>

</RelativeLayout>

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/content" />

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:minLines="3"

android:maxLines="3"

android:id="@+id/content"/>

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/button"

android:id="@+id/button"/>

</LinearLayout>

3、TableLayout(表格布局 两行两列)
[html] view plainprint?
<?xml version="1.0" encoding="utf-8"?>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

Android:stretchColumns="1">

<TableRow>

<TextView

android:text="@string/table_lable1"
android:padding="3dip"/>

<TextView

android:text="@string/table_lable2"

android:gravity="right"

android:padding="3dip"/>

</TableRow>

<TableRow>

<TextView

android:text="@string/table_lable1"
android:padding="3dip"/>

<TextView

android:text="@string/table_lable2"

android:gravity="right"

android:padding="3dip"/>

</TableRow>

</TableLayout >

4、FrameLayout(帧布局)显示控件会进行叠加,后者会叠加在前者之上

[html] view plainprint?
<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent" >

<ImageView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:src="@drawable/movie" />

<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/play"

android:layout_gravity="center"/>

</FrameLayout>

E. Android 透明度设置详解

格式:

android:background="#XXxxxxxx"(颜色可以写在color中)

说明:半透明颜色值不同于平时使用的颜色,半透明颜色值共8位,前2位是透明度,后6位是颜色。也就是说透明度和颜色结合就可以写出各种颜色的透明度。下面是透明度说明表,供大家参考。

部分透明度示例:

setAlpha()的括号中可以填0–255之间的数字。数字越大,越不透明。

注意点:
在5.0以上系统时,有些机型会出现莫名其妙的颜色值不起作用,变成透明了,也就是用此方法会导致其他共用一个资源的布局(例如:@color/white)透明度也跟着改变。比如text用上述方法设置成透明后,项目中,其他用到text颜色值的控件,都变成透明了。

原因:在布局中多个控件同时使用一个资源的时候,这些控件会共用一个状态,例如ColorState,如果你改变了一个控件的状态,其他的控件都会接收到相同的通知。这时我们可以使用mutate()方法使该控件状态不定,这样不定状态的控件就不会共享自己的状态了。

android:alpha的值为0~1之间的数。数字越大,越不透明。1表示完全不透明,0表示完全透明。

说道Activity透明,发现网上的基本上都已经过时,在有v7以上的控件都无法实现,均会报错

所以如若你的布局xml文件有 support-V7 上的控件的话,<style name="translucent">里的name要前要添加 AppTheme,如:

F. 如何设置Android中控件的颜色透明度

设置Android中控件的颜色透明度,可自由设置在layout里也可以在activity里 #ff000000 此为16进制颜色代码, 前2位ff为透明度,后6位为颜色值(000000为黑色,ffffff为白色,可以用ps等软件获取)。 透明度分为256阶(0-255),计算机上用16进制表示为(00-ff)。透明就是0阶,不透明就是255阶,如果50%透明就是127阶(256的一半当然是128,但因为是从0开始,所以实际上是127)。 0进制的255换算成16进制是ff,127换算成16进制是7f,#7f000000 代表50%透明度的黑色。 (写成#50000000当然是不行的)进制转换可使用win7自带计算器(转为科学型)。例:25%透明度的一种红色“#3ff70000

G. 如何设置Android中控件的颜色透明度

android:background="#a000"
这条属性第一位表示设置透明度0-f 越大表示越不透明
后面位表示RGB颜色的值

H. android标题栏透明度渐变

<alpha>标签为alpha透明度节点
android:fromAlpha="1.0" 设置动画起始透明度为1.0 表示完全不透明
android:toAlpha="0.0"设置动画结束透明度为0.0 表示完全透明
也就是说alpha的取值范围为0.0 - 1.0 之间

这个动画布局设置动画从完全不透明渐变到完全透明。

view plain

<?xml
version="1.0"
encoding="utf-8"?>

<alpha
xmlns:android="http://schemas.android.com/apk/res/android"

android:fromAlpha="1.0"

android:toAlpha="0.0"

android:repeatCount="infinite"

android:ration="2000">

</alpha>

代码实现

view plain

import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public
class AlphaActivity extends Activity {
/**显示动画的ImageView**/

ImageView mImageView = null;

/**透明动画**/

Animation mAnimation = null;
@Override

public
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.translate);

/**拿到ImageView对象**/

mImageView = (ImageView)findViewById(R.id.imageView);

/**加载透明动画**/

mAnimation = AnimationUtils.loadAnimation(this, R.anim.alpha);

/**播放透明动画**/

mImageView.startAnimation(mAnimation);
}
}

I. android导航栏与状态栏颜色及透明度

首先创建一个空项目,如下图

可以看到状态栏是白字黑背景, 导航栏也是白图标黑背景
嘿嘿, 我们先把状态栏隐藏掉,在添加一个ImageView, 让ImageView做背景(方便查看)

样子如下:

将状态栏和导航栏设置透明, 找到 Manifest.xml 文件, 在主题样式中修改

android:statusBarColor 设置状态栏背景色
android:navigationBarColor 同上
android:windowLightStatusBar 设置状态栏文字色, true为深色, false为白色
android:windowLightNavigationBar 同上
android:windowTranslucentStatus 设置状态栏半透明状态, true为半透明, false为不透明
android:windowTranslucentNavigation 同上

最后两个半透明状态下面没用, 可自己尝试看效果

效果图如下:

可以看到导航栏与状态栏并没有透明,原因是默认不能占用状态栏空间与导航栏空间,根布局背景为白色,所有这里显示白色
可以通过设置 getWindow().getDecorView().setSystemUiVisibility() 来适配

View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 适配状态栏空间
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 适配导航栏空间
效果如下:

J. Android 背景透明度设置总结

在需求上遇到背景设置透明度还是比较常见的,设置透明度有几种方式,但是不同的场景应用下,不同的方式可能会出现一些问题。针对开发过程中的需求做以下总结。

按钮点击

布局

输入框背景 search_title_bg

背景透明度设置比较常见,mutate()方法,可以解决背景透明状态设置异常的现象。这里只记载需求开发中遇到的问题,可能还有其他方式,欢迎分享!!

热点内容
用什么写c语言 发布:2025-05-15 21:35:56 浏览:417
linux读取u盘 发布:2025-05-15 21:32:13 浏览:507
c语言dos 发布:2025-05-15 21:18:17 浏览:663
sci编译英文 发布:2025-05-15 21:16:57 浏览:382
大猫如何设置密码 发布:2025-05-15 21:15:32 浏览:764
什么叫苹果版的和安卓版的手机 发布:2025-05-15 21:05:18 浏览:253
编程找点 发布:2025-05-15 20:43:10 浏览:587
php上传临时文件夹 发布:2025-05-15 20:43:00 浏览:657
impala数据库 发布:2025-05-15 20:42:12 浏览:649
android安装插件 发布:2025-05-15 20:41:31 浏览:241