Android APIDemo 之 001_CustomDialog
16lz
2021-01-23
近期,本人将不定期的发表android APIDemo的例子,希望大家互相交流~
ApiDemo的第一个应用:CustomDialog
运行效果:
CustomDialogActivity.java
import android.app.Activity;import android.os.Bundle;public class CustomDialogActivity extends Activity { @Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.custom_dialog_activity); }}
在drawable下创建一个filled_box.xml
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#f0600000"/> <gradient android:startColor="#FFFF0000" android:endColor="#80FF33FF" android:angle="270"/> <stroke android:width="2dp" android:color="#ee31ff5e" android:dashWidth="6dp" android:dashGap="2dp" /> <corners android:radius="20dp" /> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /></shape><!-- solid :设置背景颜色 (与gradient混用后,没有效果)gradient 产生颜色渐变 android:angle 从哪个角度开始变 貌似只有90的整数倍可以stroke:轮廓描边 → → width为描边的宽度(粗细) → → color为线条的颜色 → → dashWidth为实线部分的宽度→ → dashGap为间隔多少不描边(若为0,则为一条实线的描边,默认为0)corners : 设置圆角的大小padding : 四个方向上的间隙 -->
在value下创建一个styles.xml,在styles.xml中引用filled_box.xml
<?xml version="1.0" encoding="utf-8"?><resources> <style name="Theme.CustomDialog" parent="android:style/Theme.Dialog"> <item name="android:windowBackground">@drawable/filled_box</item> </style></resources>
activity的配置文件:custom_dialog_activity.xml
<?xml version="1.0" encoding="utf-8"?><TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/text" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_vertical|center_horizontal" android:text="@string/custom_dialog_activity_text" />
更多相关文章
- 设置android的布局文件的背景颜色为黑色
- android 获取屏幕的宽度和高度
- Android 动态设置颜色
- Android Textview实现颜色渐变滚动效果
- Android Studio——Android获取屏幕宽度的4种方法
- Android TextView内容设置超链接、颜色、字体
- Android原生AlertDialog修改标题,内容,按钮颜色,字体大小等
- Android的supportV7中默认按钮的颜色设置
- 72、android状态栏一体化,状态栏改变颜色