最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android開發(fā)之利用Activity實現Dialog對話框

 更新時間:2016年12月07日 11:13:56   投稿:daisy  
這篇文章主要給大家介紹了Android開發(fā)之如何利用Activity實現Dialog對話框效果,文中給出了詳細的示例代碼,相信對大家的理解及學習具有一定的參考借鑒價值,有需要的朋友們下面來一起看看吧。

前言

在Android中經常要使用Dialog來實現一些提示以及一些特殊的效果,而且樣式也不一樣,每次都得查一大堆資料,還不一定能解決。對話框是個好東西,創(chuàng)建簡單有實用。當下的開發(fā)中,很多的開發(fā)者反而更喜歡使用activity來代替對話框,至少筆者的團隊中,類似于升級提示或者指示頁及其他一些交互的地方,大量的把Dialog替換成activity,好處是顯而易見的,activity具有更靈活的操作和布局,另外很重要一點是,一些容易涉及內存泄漏的代碼放在activity中執(zhí)行比放在Dialog中執(zhí)行要好的多,當然這是筆者自己的觀點,文中有不對的地方,歡迎大家提出指正,好讓筆者及時改正,共同學習。

先上效果圖:

實現方法

這個對話框常常能在一些APP中遇到,首先是布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:id="@+id/activity_main"
 android:layout_width="300dp"
 android:layout_height="400dp"
 android:layout_gravity="center"
 android:background="@drawable/popup_bg"
 android:orientation="vertical"
 tools:context="com.yankee.september_2.MainActivity">
 <LinearLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_above="@+id/btn_update"
  android:layout_marginBottom="24dp"
  android:layout_marginLeft="20dp"
  android:layout_marginRight="20dp"
  android:orientation="vertical">
  <TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_gravity="center_horizontal"
   android:text="Version"
   android:textColor="#53BAF8"
   android:textSize="14sp" />
  <ScrollView
   android:layout_width="match_parent"
   android:layout_height="100dp"
   android:layout_gravity="center_horizontal"
   android:layout_marginTop="12dp">
   <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Nowadays, when it comes to the issues of robots, individuals' opinions vary from person to person。 Some people believe that robots will enlighten our life, while other are worried about that they will ruin the whole world。 As I see, the increasing number of robots has the power to alter everything in the coming future entirely。"
    android:textColor="#404040"
    android:textSize="12sp" />
  </ScrollView>
 </LinearLayout>
 <Button
  android:id="@+id/btn_update"
  android:layout_width="130dp"
  android:layout_height="32dp"
  android:layout_alignParentBottom="true"
  android:layout_centerHorizontal="true"
  android:layout_marginBottom="16dp"
  android:background="@color/colorAccent"
  android:gravity="center"
  android:text="Update now"
  android:textColor="#FFFFFF"
  android:textSize="14sp" />
</RelativeLayout>

布局代碼中需要注意的是,這個布局的大小是寫死的,因為從代碼中可以看出,對話框的鏤空效果其實是一張背景圖產生的,辛苦美術但是爽了程序員。

第二步:接著就是在manifest文件的操作了,把對應的activity的theme設置為自定義的主題即可,背景設為透明,去掉標題,注意,這個主題繼承自對話框的主題。

manifest:

<activity
 android:name=".MainActivity"
 android:screenOrientation="portrait"
 android:theme="@style/TipDialog">
</activity>

styles.xml:

<style name="TipDialog" parent="@android:style/Theme.Dialog">
 <item name="android:windowNoTitle">true</item>
 <item name="android:windowBackground">@android:color/transparent</item>
</style>

最后就沒有最后了,還有一點,就是讓當前這個activity繼承自Activity,而不是AppCompatActivity,否則會報主題的錯誤。

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流。

相關文章

  • Android控件之ImageView用法實例分析

    Android控件之ImageView用法實例分析

    這篇文章主要介紹了Android控件之ImageView用法,以實例形式較為詳細的分析了ImageView控件用于顯示圖片的使用方法,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-09-09
  • Android 輕松實現圖片倒影效果實例代碼

    Android 輕松實現圖片倒影效果實例代碼

    這篇文章主要介紹了Android 輕松實現圖片倒影效果實例代碼,有需要的朋友可以參考一下
    2014-01-01
  • Android實現圖片輪播效果

    Android實現圖片輪播效果

    這篇文章主要為大家詳細介紹了Android實現圖片輪播效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2015-12-12
  • Android實現布局全屏

    Android實現布局全屏

    這篇文章主要為大家詳細介紹了Android實現布局全屏,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-05-05
  • Android開發(fā)常用標簽小結

    Android開發(fā)常用標簽小結

    這篇文章主要介紹了Android開發(fā)常用標簽,分析總結了Android開發(fā)中常見標簽的使用技巧,需要的朋友可以參考下
    2015-05-05
  • Android使用廣播發(fā)送消息

    Android使用廣播發(fā)送消息

    這篇文章主要為大家詳細介紹了Android使用廣播發(fā)送消息,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • Android基礎之使用Fragment適應不同屏幕和分辨率(分享)

    Android基礎之使用Fragment適應不同屏幕和分辨率(分享)

    以下是對Fragment的使用進行了詳細的分析介紹,需要的朋友可以過來參考下
    2013-07-07
  • flutter?Bloc?add兩次只響應一次問題解析

    flutter?Bloc?add兩次只響應一次問題解析

    這篇文章主要為大家介紹了flutter?Bloc?add兩次只響應一次問題解析記錄,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-11-11
  • Android 獲取設備屏幕大小的幾種方法總結

    Android 獲取設備屏幕大小的幾種方法總結

    這篇文章主要介紹了Android 獲取設備屏幕大小的幾種方法總結的相關資料,需要的朋友可以參考下
    2017-05-05
  • Android使用Intent顯示實現頁面跳轉

    Android使用Intent顯示實現頁面跳轉

    這篇文章主要為大家詳細介紹了Android使用Intent顯示實現頁面跳轉,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-08-08

最新評論

沾益县| 大竹县| 兰西县| 白河县| 灵宝市| 司法| 三门峡市| 泰安市| 安新县| 泗阳县| 重庆市| 曲沃县| 望江县| 大竹县| 天门市| 定安县| 鄯善县| 德化县| 东乡县| 广南县| 利川市| 蒙山县| 鄄城县| 廊坊市| 酒泉市| 凯里市| 枣阳市| 平湖市| 镇安县| 武冈市| 南皮县| 灌阳县| 旅游| 木里| 河东区| 宣恩县| 岗巴县| 正镶白旗| 广平县| 社旗县| 吐鲁番市|