推荐安卓开发神器(里面有各种UI特效和android代码库实例)
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>标签中添加
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,内容如下:
view plaincopy to clipboardprint? <?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> <?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代码如下:
view plaincopy to clipboardprint? 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(); } } 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(); } }
相关推荐
android dialog-------普通对话框
React Native Android Location Services对话框 从Android位置服务打开对话框的React-Native组件安装大多是自动安装(推荐) yarn add react-native-android-location-services-dialog-box 要么npm install react-...
遮罩层弹出半透明dialog,很fashion。
各种android弹出dialog效果以及各种dialog样式各种android弹出dialog效果以及各种dialog样式各种android弹出dialog效果以及各种dialog样式各种android弹出dialog效果以及各种dialog样式各种android弹出dialog效果...
重载dialog,是周围出现透明磨砂的效果。点击dialog以外区域自动退出。
Android---UI篇---Dialog(对话框)
Android入门开发实例--Dialog 对话框应用
文档介绍了Android开发教程之一:控制Dialog 的背景方法,1.定义一个无背景主题主题,2.创建Dialog,二:控制Dialog 以及内部控件的背景方法,Android开发教程之三:去掉边框、title 等参数
Android项目的筛选对话框活动
Simple Android Library that provide you a custom dialog that allow you to set a start time and end time. Screenshot Install Add this to your project build.gradle allprojects { ...
普通对话框,日期选择对话框,时间选择对话框,自定义对话框
Android Stduio的代码,为采用dialog的Activity,已经在android 4.3上的工业平板电脑上跑通。需要在手机端跑的,需要再确认各个手机品牌的权限。
安卓Android源码——-styled-dialogs可自定义样式的dialog.zip
Android Dialog设置透明背景以及位置
android Dialog效果集合【全】
自定义对话框样式,以及对话框的加载动画,告别Android默认丑陋的对话框!
android dialog向上弹效果,其实动画的效果改变就好
•Android---UI篇---Dialog(对话框) • •Android---UI篇---AutoCompleteTextView(自动提示) • •Android---UI篇---Toast(提示) • •Android---UI篇---Button(按钮) • •Android---UI篇---TextView...