Android有趣的全透明效果--Activity及Dialog的全透明(附android系统自带图标大全)[转]

原文地址:http://blog.csdn.net/sodino/article/details/5822147

1.Activity全透明

同学zzm给了这个有趣的代码,现在公布出来。

先在res/values下建colors.xml文件,写入:

<? xml   version = "1.0"   encoding = "UTF-8" ?>
< resources >
    < color   name = "transparent" > #9000 </ color >
</ resources >   

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

再在res/values/下建styles.xml,设置程序的风格

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Transparent">
        <item name="android:windowBackground">@color/transparent</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item>
    </style>
</resources>

最后一步,把这个styles.xml用在相应的Activity上。即在AndroidManifest.xml中的任 意<activity>标签中添加

  1. android:theme = "@style/transparent"

如果想设置所有的activity都使用这个风格,可以把这句标签语句添加在<application>中。

最后运行程序,哈哈,是不是发现整个界面都被蒙上一层半透明了。最后可以把背景色#9000换成#0000,运行程序后,就全透明了,看得见背景下 的所有东西可以却都操作无效。呵呵....

2.Dialog全透明

1.准备保留边框的全透明素材如下图:

2.在values中新建一styles.xml文件,内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <style name="TANCStyle" parent="@android:style/Theme.Dialog">
        <!-- 更换背景图片实现全透明 -->
        <item name="android:windowBackground">@drawable/panel_background_sodino1</item>
        <!-- 屏幕背景不变暗 -->
        <item name="android:backgroundDimEnabled">false</item>
        <!-- 更改对话框标题栏 -->
        <item name="android:windowTitleStyle">@style/TitleStyle</item>
    </style>
    <style name="TitleStyle" parent="@android:style/DialogWindowTitle">
        <item name="android:textAppearance">@style/TitleText</item>
    </style>
    <style name="TitleText" parent="@android:style/TextAppearance.DialogWindowTitle">
        <!-- 设置Dialog标题栏文字颜色。 -->
        <item name="android:textColor">#000</item>
    </style>
</resources>

3.在layout文件夹下新建一文件句为main_dialog.xml,内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#0000">
    <ScrollView android:id="@+id/ScrollView01"
        android:layout_width="wrap_content"
        android:layout_height="200px"
        android:layout_below="@+id/ImageView01"
        android:background="#0000">
        <TextView android:id="@+id/TextView01"
            android:text="SodinoText"
            android:textColor="#f000"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#0000"
        ></TextView>
    </ScrollView>
    <Button android:id="@+id/btnCancel"
        android:layout_below="@id/ScrollView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="Cancel">
    </Button>
</RelativeLayout>  

4.Activity代码如下:

package lab.sodino.tanc;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class TANCAct extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button btnShow = (Button) findViewById(R.id.btnShow);
        btnShow.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View view) {
                showTANC(
                        "This is my custom dialog box",
                        "TextContent/nWhen a dialog is requested for the first time, Android calls onCreateDialog(int)  from your Activity, which is where you should instantiate the Dialog. This callback method is passed the same ID that you passed to showDialog(int). After you create the Dialog, return the object at the end of the method.",
                        "http://blog.csdn.net/sodino");
            }
        });
    }
    private void showTANC(String header, String content, String url) {
        final Dialog dialog = new Dialog(this, R.style.TANCStyle);
        dialog.setContentView(R.layout.main_dialog);
        dialog.setTitle(header);
        dialog.setCancelable(true);
        TextView textView01 = (TextView) dialog.findViewById(R.id.TextView01);
        textView01.setText(content + content + content);
        Button btnCancel = (Button) dialog.findViewById(R.id.btnCancel);
        btnCancel.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View view) {
                dialog.cancel();
            }
        });
        dialog.show();
    }
}  

最后效果图:

时间: 2024-08-03 01:37:13

Android有趣的全透明效果--Activity及Dialog的全透明(附android系统自带图标大全)[转]的相关文章

[转]Android有趣的全透明效果--Activity及Dialog的全透明(附android系统自带图标大全

原文:http://blog.csdn.net/sodino/article/details/5822147 1.Activity全透明 同学zzm给了这个有趣的代码,现在公布出来. 先在res/values下建colors.xml文件,写入: <? xml   version = "1.0"   encoding = "UTF-8" ?>    < resources >        < color   name = "t

android系统自带图标

android:src="@android:drawable/ic_media_rew" android系统自带图标

android系统自带图标集合(android.R.drawable查看)

alert_dark_frame alert_light_frame arrow_down_float arrow_up_float bottom_bar btn_default btn_default_small btn_dialog btn_dropdown btn_minus btn_plus btn_radio btn_star btn_star_big_off btn_star_big_on button_onoff_indicator_off button_onoff_indicat

网页设计中透明效果的使用技巧

在网页设计中使用透明效果是件既美观又冒险的事儿.透明效果的使用是把色块,文本或图像“变薄”或者降低饱和度,使颜色变浅透明,这样下个图层的内 容就能穿透显示出来.这种方法如果用好了,效果将会特别棒——能突出显示文本或者在图像的特定区域形成焦点.但设计者在运用透明效果时要特别小心,因为这 么做可能会影响页面的可读性.要是框和文本的透明度不对,更可能会影响到整体的设计. 下文是一些注意事项以及巧妙运用透明效果的成功案例. 用“透明效果”来制造对比 使 用透明效果最大的优点是可以形成对比.设计者可以在图

Android 编程下实现 Activity 的透明效果

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

Android浏览图片,点击放大至全屏效果

最近做一个项目类似于QQ空间,做到照片浏览的功能,对于QQ空间中点击图片放大至全屏,感觉效果很赞,于是也做了个类似的效果.如下. 我不知道QQ那个是怎么做的,我的思路如下: 首先,从图片缩略界面跳转到图片详情页面,应该是从一个Activity跳转到另外一个Activity,应该图片详情页面也有很多操作,用View或者Dialog不是很好.所以现在难点就是,如何使得前一个界面的ImageView在另外一个界面做缩放切割动画. 一般缩略界面的ImageView的是如上图所示的正方形的,并且是CENT

Android开发实例透明效果设置方法

没什么android开发经验的朋友来说,实现透明效果是有一定难度的,我看见麦子学院android开发视频上面讲了三种方法来实现透明效果,这三种方法非常不错,嘿嘿,就抄下来分享给大家. 1.设置alpha View v = findViewById(R.id.content);/到你要设透明背景的layout 的id  v.getBackground().setAlpha(100);//0~255透明度值  2.用ARGB来控制 半透明<Button android:background="

Android课程---Android设置透明效果的三种方法(转)

1.使用Android系统自带的透明效果资源 <Button  android:background="@android:color/transparent"/> 2.使用ARGB来控制 半透明 <Button  android:background="#e0000000"/> 透明 <Button  android:background="#00000000"/> 颜色和不透明度 (alpha) 值以十六进制

android:android:background=&quot;#00000000&quot;,透明效果

ImageButton中设置 android:background="#00000000",可以达到透明效果 具体的源码 管理-->文件中的 viewpager0829.rar