• Api demo源码学习(2)App/Activity/Custom Dialog 自定义Activity样式


    这一节比较简单,让Activity以自定义的Dialog形式展现出来,只需要配置一系列的xml文档即可。一直没有做过比较大型的项目,翻看apidemo的xml文档才知道配置工作也有很大的工作量。xml中的许多标签之前都没有接触过。

    Activity不需要做任何修改。

    首先配置AndroidManifest.xml文档,添加一条属性,指定该antivity以指定的style显示:
    android:theme="@style/Theme.CustomDialog"

    然后在res/values 目录下建立styles.xml文件,建立一个style样式,该style样式继承于android自带的Theme.Dialog样式
    <?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

    在res/drawable 目录下建立filled_box.xml文件,定义一个shape,用来规定activity的外框样式
    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <solid android:color="#f0600000"/>
        <stroke android:width="3dp" color="#ffff8080"/>
        <corners android:radius="3dp" />
        <padding android:left="10dp" android:top="10dp"
            android:right="10dp" android:bottom="10dp" />
    </shape>

    最后修改res/layout目录下的main.xml文件,规定textview的显示格式
    <?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"
        android:text="show Custom Dialog"/>
     
    通过以上配置,就可以完成activity以指定的样式呈现。

  • 相关阅读:
    动态规划例题
    c++ 进制转换函数
    约瑟夫问题
    set的基本使用
    stl中的二分查找
    1.生成的接口返回参数不包括系统自带的参数
    查看被锁定的表,并解锁
    添加、修改表中的字段
    NPOI简单示例2—合并表头
    NPOI简单示例
  • 原文地址:https://www.cnblogs.com/xutao1988/p/2286809.html
Copyright © 2020-2023  润新知