• android创建自定义对话框


    创建如下自定义对话框:

    JAVA代码

    LayoutInflater li = LayoutInflater.from(TagActivity. this);  //NOTE
    final View TestView = li.inflate(R.layout.tag_dialog, null);
    dialog =  new Dialog(TagActivity. this, R.style.dialog);
    dialog.setContentView(TestView);
    dialog.setCancelable( true);
    dialog.show();

    R.layout.tag_dialog如下

    <?xml version= "1.0"  encoding= "utf-8" ?>
    <LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android"  android:layout_width= "match_parent"  android:layout_height= "match_parent"  android:orientation= "vertical" >
       <LinearLayout android:layout_height= "wrap_content"  android:layout_width= "fill_parent" >
         <TextView android:id= "@+id/title"  android:layout_height= "wrap_content"  android:layout_width= "fill_parent"  android:gravity= "center"  android:textColor= "@color/white"  android:paddingTop= "15dp" ></TextView>
       </LinearLayout>
       <LinearLayout android:layout_width= "200dp"  android:layout_height= "200dp"  android:orientation= "vertical"  android:paddingLeft= "10dp"  android:paddingRight= "10dp"  android:paddingTop= "10dp" >
         <EditText android:id= "@+id/name"  android:layout_width= "fill_parent"  android:layout_height= "wrap_content"  android:background= "@color/transparent"  android:textColor= "@color/white"  android:hint= "输入消息内容"  android:textColorHint= "@color/white" ></EditText>
       </LinearLayout>
       <LinearLayout android:layout_width= "fill_parent"  android:layout_height= "wrap_content"  android:orientation= "horizontal"  android:layout_marginBottom= "10dp" >
         <RelativeLayout android:layout_width= "fill_parent"  android:layout_height= "wrap_content"  android:layout_weight= "1" >
           <ImageButton android:id= "@+id/sure"  android:layout_width= "wrap_content"  android:layout_height= "wrap_content"  android:src= "@drawable/sure"  android:background= "@drawable/btn_click_background"  android:layout_centerHorizontal= "true" ></ImageButton>
         </RelativeLayout>
         <RelativeLayout android:layout_width= "fill_parent"  android:layout_height= "wrap_content"  android:layout_weight= "1" >
           <ImageButton android:id= "@+id/cancel"  android:layout_width= "wrap_content"  android:layout_height= "wrap_content"  android:src= "@drawable/cancel"  android:background= "@drawable/btn_click_background"  android:layout_centerHorizontal= "true" ></ImageButton>
         </RelativeLayout>
       </LinearLayout>
    </LinearLayout>

    R.style.dialog文件如下

    <!-- 下面是对话框对应的style -->
    <style name= "dialog"  parent= "@android:style/Theme.Dialog" >
       <item name= "android:windowFrame" >@null </item>
       <item name= "android:windowIsFloating" >true </item>
       <item name= "android:windowIsTranslucent" >true </item>
       <item name= "android:windowNoTitle" >true </item>
       <!--<item name="android:background">@android:color/transparent</item>-->
       <item name= "android:background" >@android:color /transparent </item>
       <item name= "android:windowBackground" >@drawable /dialog_bg </item>
       <item name= "android:backgroundDimEnabled" >true </item>
       <item name= "android:backgroundDimAmount" >0.6 </item>
       <item name= "android:windowFullscreen" >true </item>
    </style>
  • 相关阅读:
    绑定方法、非绑定方法与静态方法
    封装、隐藏和property装饰器
    自己动手写中文分词解析器完整教程,并对出现的问题进行探讨和解决(附完整c#代码和相关dll文件、txt文件下载)
    SASS -- 基本认识
    网易新闻页面信息抓取 -- htmlagilitypack搭配scrapysharp
    爬虫技术(四)-- 简单爬虫抓取示例(附c#代码)
    c# -- 读取文件夹中的所有文件(备忘)
    爬虫技术(五)-- 模拟简单浏览器(附c#代码)
    爬虫技术(六)-- 使用HtmlAgilityPack获取页面链接(附c#代码及插件下载)
    关于引用mshtml的问题
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3177731.html
Copyright © 2020-2023  润新知