Android实践-自定义dialog从屏幕底部弹出并且充满屏幕宽度

转载出处http://blog.csdn.net/nugongahou110

通常我们使用dialog的时候会遇到一些问题,比如我想用自己定义的布局来替代系统那个黑乎乎的布局时我要怎么做?我想要指定dialog从底部弹出而不是在屏幕中央弹出要怎么做?我设置了dialog布局的宽度为填充父窗体然而实际效果却不是充满全屏的,这时我该怎么做?

我们先来看一个例子:


首先我们先来定义一个dialog的布局

<a target=_blank id="L1" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L1" rel="#L1" style="text-decoration: none; color: rgb(12, 137, 207);">  1</a>
<a target=_blank id="L2" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L2" rel="#L2" style="text-decoration: none; color: rgb(12, 137, 207);">  2</a>
<a target=_blank id="L3" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L3" rel="#L3" style="text-decoration: none; color: rgb(12, 137, 207);">  3</a>
<a target=_blank id="L4" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L4" rel="#L4" style="text-decoration: none; color: rgb(12, 137, 207);">  4</a>
<a target=_blank id="L5" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L5" rel="#L5" style="text-decoration: none; color: rgb(12, 137, 207);">  5</a>
<a target=_blank id="L6" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L6" rel="#L6" style="text-decoration: none; color: rgb(12, 137, 207);">  6</a>
<a target=_blank id="L7" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L7" rel="#L7" style="text-decoration: none; color: rgb(12, 137, 207);">  7</a>
<a target=_blank id="L8" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L8" rel="#L8" style="text-decoration: none; color: rgb(12, 137, 207);">  8</a>
<a target=_blank id="L9" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L9" rel="#L9" style="text-decoration: none; color: rgb(12, 137, 207);">  9</a>
<a target=_blank id="L10" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L10" rel="#L10" style="text-decoration: none; color: rgb(12, 137, 207);"> 10</a>
<a target=_blank id="L11" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L11" rel="#L11" style="text-decoration: none; color: rgb(12, 137, 207);"> 11</a>
<a target=_blank id="L12" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L12" rel="#L12" style="text-decoration: none; color: rgb(12, 137, 207);"> 12</a>
<a target=_blank id="L13" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L13" rel="#L13" style="text-decoration: none; color: rgb(12, 137, 207);"> 13</a>
<a target=_blank id="L14" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L14" rel="#L14" style="text-decoration: none; color: rgb(12, 137, 207);"> 14</a>
<a target=_blank id="L15" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L15" rel="#L15" style="text-decoration: none; color: rgb(12, 137, 207);"> 15</a>
<a target=_blank id="L16" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L16" rel="#L16" style="text-decoration: none; color: rgb(12, 137, 207);"> 16</a>
<a target=_blank id="L17" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L17" rel="#L17" style="text-decoration: none; color: rgb(12, 137, 207);"> 17</a>
<a target=_blank id="L18" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L18" rel="#L18" style="text-decoration: none; color: rgb(12, 137, 207);"> 18</a>
<a target=_blank id="L19" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L19" rel="#L19" style="text-decoration: none; color: rgb(12, 137, 207);"> 19</a>
<a target=_blank id="L20" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L20" rel="#L20" style="text-decoration: none; color: rgb(12, 137, 207);"> 20</a>
<a target=_blank id="L21" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L21" rel="#L21" style="text-decoration: none; color: rgb(12, 137, 207);"> 21</a>
<a target=_blank id="L22" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L22" rel="#L22" style="text-decoration: none; color: rgb(12, 137, 207);"> 22</a>
<a target=_blank id="L23" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L23" rel="#L23" style="text-decoration: none; color: rgb(12, 137, 207);"> 23</a>
<a target=_blank id="L24" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L24" rel="#L24" style="text-decoration: none; color: rgb(12, 137, 207);"> 24</a>
<a target=_blank id="L25" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L25" rel="#L25" style="text-decoration: none; color: rgb(12, 137, 207);"> 25</a>
<a target=_blank id="L26" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L26" rel="#L26" style="text-decoration: none; color: rgb(12, 137, 207);"> 26</a>
<a target=_blank id="L27" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L27" rel="#L27" style="text-decoration: none; color: rgb(12, 137, 207);"> 27</a>
<a target=_blank id="L28" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L28" rel="#L28" style="text-decoration: none; color: rgb(12, 137, 207);"> 28</a>
           
           
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android"
android:orientation= "horizontal" android:layout_width= "match_parent"
android:layout_height= "match_parent"
>
<Button
android:id= "@+id/bt_weixin"
android:layout_width= "0dp"
android:layout_height= "wrap_content"
android:text= "微信"
android:layout_weight= "1"
android:background= "@color/material_blue_grey_800" />
<Button
android:id= "@+id/bt_weibo"
android:layout_width= "0dp"
android:layout_weight= "1"
android:layout_height= "wrap_content"
android:background= "#ef3254"
android:text= "微博" />
<Button
android:id= "@+id/bt_pengyouquan"
android:layout_width= "0dp"
android:layout_weight= "1"
android:layout_height= "wrap_content"
android:background= "#ef6d03"
android:text= "朋友圈" />
</LinearLayout>
 来自CODE的代码片
my_dialog.xml
activity_main.xml非常简单,只有一个button

<a target=_blank id="L1" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L1" rel="#L1" style="text-decoration: none; color: rgb(12, 137, 207);">  1</a>
<a target=_blank id="L2" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L2" rel="#L2" style="text-decoration: none; color: rgb(12, 137, 207);">  2</a>
<a target=_blank id="L3" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L3" rel="#L3" style="text-decoration: none; color: rgb(12, 137, 207);">  3</a>
<a target=_blank id="L4" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L4" rel="#L4" style="text-decoration: none; color: rgb(12, 137, 207);">  4</a>
<a target=_blank id="L5" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L5" rel="#L5" style="text-decoration: none; color: rgb(12, 137, 207);">  5</a>
<a target=_blank id="L6" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L6" rel="#L6" style="text-decoration: none; color: rgb(12, 137, 207);">  6</a>
<a target=_blank id="L7" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L7" rel="#L7" style="text-decoration: none; color: rgb(12, 137, 207);">  7</a>
<a target=_blank id="L8" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L8" rel="#L8" style="text-decoration: none; color: rgb(12, 137, 207);">  8</a>
<a target=_blank id="L9" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L9" rel="#L9" style="text-decoration: none; color: rgb(12, 137, 207);">  9</a>
<a target=_blank id="L10" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L10" rel="#L10" style="text-decoration: none; color: rgb(12, 137, 207);"> 10</a>
<a target=_blank id="L11" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L11" rel="#L11" style="text-decoration: none; color: rgb(12, 137, 207);"> 11</a>
<a target=_blank id="L12" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L12" rel="#L12" style="text-decoration: none; color: rgb(12, 137, 207);"> 12</a>
<a target=_blank id="L13" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L13" rel="#L13" style="text-decoration: none; color: rgb(12, 137, 207);"> 13</a>
           
           
<RelativeLayout xmlns:android= "http://schemas.android.com/apk/res/android"
xmlns:tools= "http://schemas.android.com/tools" android:layout_width= "match_parent"
android:layout_height= "match_parent"
>
<Button
android:id= "@+id/share"
android:text= "分享" android:layout_width= "wrap_content"
android:layout_height= "wrap_content"
/>
</RelativeLayout>
 来自CODE的代码片
activity_main.xml
接着我们要在res/values/styles.xml下定义dialog的样式以及dialog弹出时的动画

<a target=_blank id="L1" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L1" rel="#L1" style="text-decoration: none; color: rgb(12, 137, 207);">  1</a>
<a target=_blank id="L2" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L2" rel="#L2" style="text-decoration: none; color: rgb(12, 137, 207);">  2</a>
<a target=_blank id="L3" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L3" rel="#L3" style="text-decoration: none; color: rgb(12, 137, 207);">  3</a>
<a target=_blank id="L4" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L4" rel="#L4" style="text-decoration: none; color: rgb(12, 137, 207);">  4</a>
<a target=_blank id="L5" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L5" rel="#L5" style="text-decoration: none; color: rgb(12, 137, 207);">  5</a>
<a target=_blank id="L6" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L6" rel="#L6" style="text-decoration: none; color: rgb(12, 137, 207);">  6</a>
<a target=_blank id="L7" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L7" rel="#L7" style="text-decoration: none; color: rgb(12, 137, 207);">  7</a>
<a target=_blank id="L8" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L8" rel="#L8" style="text-decoration: none; color: rgb(12, 137, 207);">  8</a>
<a target=_blank id="L9" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L9" rel="#L9" style="text-decoration: none; color: rgb(12, 137, 207);">  9</a>
<a target=_blank id="L10" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L10" rel="#L10" style="text-decoration: none; color: rgb(12, 137, 207);"> 10</a>
<a target=_blank id="L11" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L11" rel="#L11" style="text-decoration: none; color: rgb(12, 137, 207);"> 11</a>
<a target=_blank id="L12" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L12" rel="#L12" style="text-decoration: none; color: rgb(12, 137, 207);"> 12</a>
<a target=_blank id="L13" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L13" rel="#L13" style="text-decoration: none; color: rgb(12, 137, 207);"> 13</a>
<a target=_blank id="L14" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L14" rel="#L14" style="text-decoration: none; color: rgb(12, 137, 207);"> 14</a>
<a target=_blank id="L15" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L15" rel="#L15" style="text-decoration: none; color: rgb(12, 137, 207);"> 15</a>
<a target=_blank id="L16" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L16" rel="#L16" style="text-decoration: none; color: rgb(12, 137, 207);"> 16</a>
           
           
<!-- 弹出框动画 由下至上 -->
<style name= "dialogStyle" parent= "@android:style/Animation.Dialog" >
<item name= "@android:windowEnterAnimation" >@anim/dialog_enter </item>
<!-- 进入时的动画 -->
<item name= "@android:windowExitAnimation" >@anim/dialog_exit </item>
<!-- 退出时的动画 -->
</style>
<!-- 对话框样式 -->
<style name= "Theme.Light.Dialog" parent= "android:style/Theme.Dialog" >
<item name= "android:windowBackground" >@android:color/transparent </item>
<item name= "android:windowNoTitle" >true </item>
<item name= "android:windowIsFloating" >true </item>
<item name= "android:windowContentOverlay" >@null </item>
<item name= "android:scrollHorizontally" >true </item>
</style>
 来自CODE的代码片
styles.xml
接着我们在res下新建一个anim文件夹,在res/values/anim下新建两个xml文件


dialog_enter.xml和dialog_exit.xml如下

<a target=_blank id="L1" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L1" rel="#L1" style="text-decoration: none; color: rgb(12, 137, 207);"> 1</a>
<a target=_blank id="L2" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L2" rel="#L2" style="text-decoration: none; color: rgb(12, 137, 207);"> 2</a>
<a target=_blank id="L3" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L3" rel="#L3" style="text-decoration: none; color: rgb(12, 137, 207);"> 3</a>
<a target=_blank id="L4" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L4" rel="#L4" style="text-decoration: none; color: rgb(12, 137, 207);"> 4</a>
<a target=_blank id="L5" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L5" rel="#L5" style="text-decoration: none; color: rgb(12, 137, 207);"> 5</a>
           
           
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android= "http://schemas.android.com/apk/res/android" >
<translate android:fromYDelta= "100%"
android:duration= "600" ></translate>
</set>
 来自CODE的代码片
dialog_enter.xml
<a target=_blank id="L1" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L1" rel="#L1" style="text-decoration: none; color: rgb(12, 137, 207);"> 1</a>
<a target=_blank id="L2" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L2" rel="#L2" style="text-decoration: none; color: rgb(12, 137, 207);"> 2</a>
<a target=_blank id="L3" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L3" rel="#L3" style="text-decoration: none; color: rgb(12, 137, 207);"> 3</a>
<a target=_blank id="L4" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L4" rel="#L4" style="text-decoration: none; color: rgb(12, 137, 207);"> 4</a>
<a target=_blank id="L5" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L5" rel="#L5" style="text-decoration: none; color: rgb(12, 137, 207);"> 5</a>
           
           
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android= "http://schemas.android.com/apk/res/android" >
<translate android:toYDelta= "100%"
android:duration= "600" ></translate>
</set>
 来自CODE的代码片
dialog_exit.xml

最后是MainActivity.Java

<a target=_blank id="L1" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L1" rel="#L1" style="text-decoration: none; color: rgb(12, 137, 207);">  1</a>
<a target=_blank id="L2" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L2" rel="#L2" style="text-decoration: none; color: rgb(12, 137, 207);">  2</a>
<a target=_blank id="L3" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L3" rel="#L3" style="text-decoration: none; color: rgb(12, 137, 207);">  3</a>
<a target=_blank id="L4" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L4" rel="#L4" style="text-decoration: none; color: rgb(12, 137, 207);">  4</a>
<a target=_blank id="L5" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L5" rel="#L5" style="text-decoration: none; color: rgb(12, 137, 207);">  5</a>
<a target=_blank id="L6" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L6" rel="#L6" style="text-decoration: none; color: rgb(12, 137, 207);">  6</a>
<a target=_blank id="L7" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L7" rel="#L7" style="text-decoration: none; color: rgb(12, 137, 207);">  7</a>
<a target=_blank id="L8" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L8" rel="#L8" style="text-decoration: none; color: rgb(12, 137, 207);">  8</a>
<a target=_blank id="L9" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L9" rel="#L9" style="text-decoration: none; color: rgb(12, 137, 207);">  9</a>
<a target=_blank id="L10" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L10" rel="#L10" style="text-decoration: none; color: rgb(12, 137, 207);"> 10</a>
<a target=_blank id="L11" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L11" rel="#L11" style="text-decoration: none; color: rgb(12, 137, 207);"> 11</a>
<a target=_blank id="L12" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L12" rel="#L12" style="text-decoration: none; color: rgb(12, 137, 207);"> 12</a>
<a target=_blank id="L13" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L13" rel="#L13" style="text-decoration: none; color: rgb(12, 137, 207);"> 13</a>
<a target=_blank id="L14" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L14" rel="#L14" style="text-decoration: none; color: rgb(12, 137, 207);"> 14</a>
<a target=_blank id="L15" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L15" rel="#L15" style="text-decoration: none; color: rgb(12, 137, 207);"> 15</a>
<a target=_blank id="L16" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L16" rel="#L16" style="text-decoration: none; color: rgb(12, 137, 207);"> 16</a>
<a target=_blank id="L17" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L17" rel="#L17" style="text-decoration: none; color: rgb(12, 137, 207);"> 17</a>
<a target=_blank id="L18" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L18" rel="#L18" style="text-decoration: none; color: rgb(12, 137, 207);"> 18</a>
<a target=_blank id="L19" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L19" rel="#L19" style="text-decoration: none; color: rgb(12, 137, 207);"> 19</a>
<a target=_blank id="L20" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L20" rel="#L20" style="text-decoration: none; color: rgb(12, 137, 207);"> 20</a>
<a target=_blank id="L21" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L21" rel="#L21" style="text-decoration: none; color: rgb(12, 137, 207);"> 21</a>
<a target=_blank id="L22" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L22" rel="#L22" style="text-decoration: none; color: rgb(12, 137, 207);"> 22</a>
<a target=_blank id="L23" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L23" rel="#L23" style="text-decoration: none; color: rgb(12, 137, 207);"> 23</a>
<a target=_blank id="L24" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L24" rel="#L24" style="text-decoration: none; color: rgb(12, 137, 207);"> 24</a>
<a target=_blank id="L25" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L25" rel="#L25" style="text-decoration: none; color: rgb(12, 137, 207);"> 25</a>
<a target=_blank id="L26" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L26" rel="#L26" style="text-decoration: none; color: rgb(12, 137, 207);"> 26</a>
<a target=_blank id="L27" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L27" rel="#L27" style="text-decoration: none; color: rgb(12, 137, 207);"> 27</a>
<a target=_blank id="L28" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L28" rel="#L28" style="text-decoration: none; color: rgb(12, 137, 207);"> 28</a>
<a target=_blank id="L29" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L29" rel="#L29" style="text-decoration: none; color: rgb(12, 137, 207);"> 29</a>
<a target=_blank id="L30" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L30" rel="#L30" style="text-decoration: none; color: rgb(12, 137, 207);"> 30</a>
<a target=_blank id="L31" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L31" rel="#L31" style="text-decoration: none; color: rgb(12, 137, 207);"> 31</a>
<a target=_blank id="L32" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L32" rel="#L32" style="text-decoration: none; color: rgb(12, 137, 207);"> 32</a>
<a target=_blank id="L33" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L33" rel="#L33" style="text-decoration: none; color: rgb(12, 137, 207);"> 33</a>
<a target=_blank id="L34" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L34" rel="#L34" style="text-decoration: none; color: rgb(12, 137, 207);"> 34</a>
<a target=_blank id="L35" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L35" rel="#L35" style="text-decoration: none; color: rgb(12, 137, 207);"> 35</a>
<a target=_blank id="L36" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L36" rel="#L36" style="text-decoration: none; color: rgb(12, 137, 207);"> 36</a>
<a target=_blank id="L37" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L37" rel="#L37" style="text-decoration: none; color: rgb(12, 137, 207);"> 37</a>
<a target=_blank id="L38" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L38" rel="#L38" style="text-decoration: none; color: rgb(12, 137, 207);"> 38</a>
<a target=_blank id="L39" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L39" rel="#L39" style="text-decoration: none; color: rgb(12, 137, 207);"> 39</a>
<a target=_blank id="L40" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L40" rel="#L40" style="text-decoration: none; color: rgb(12, 137, 207);"> 40</a>
<a target=_blank id="L41" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L41" rel="#L41" style="text-decoration: none; color: rgb(12, 137, 207);"> 41</a>
<a target=_blank id="L42" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L42" rel="#L42" style="text-decoration: none; color: rgb(12, 137, 207);"> 42</a>
<a target=_blank id="L43" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L43" rel="#L43" style="text-decoration: none; color: rgb(12, 137, 207);"> 43</a>
<a target=_blank id="L44" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L44" rel="#L44" style="text-decoration: none; color: rgb(12, 137, 207);"> 44</a>
<a target=_blank id="L45" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L45" rel="#L45" style="text-decoration: none; color: rgb(12, 137, 207);"> 45</a>
<a target=_blank id="L46" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L46" rel="#L46" style="text-decoration: none; color: rgb(12, 137, 207);"> 46</a>
<a target=_blank id="L47" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L47" rel="#L47" style="text-decoration: none; color: rgb(12, 137, 207);"> 47</a>
<a target=_blank id="L48" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L48" rel="#L48" style="text-decoration: none; color: rgb(12, 137, 207);"> 48</a>
<a target=_blank id="L49" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L49" rel="#L49" style="text-decoration: none; color: rgb(12, 137, 207);"> 49</a>
<a target=_blank id="L50" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L50" rel="#L50" style="text-decoration: none; color: rgb(12, 137, 207);"> 50</a>
<a target=_blank id="L51" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L51" rel="#L51" style="text-decoration: none; color: rgb(12, 137, 207);"> 51</a>
<a target=_blank id="L52" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L52" rel="#L52" style="text-decoration: none; color: rgb(12, 137, 207);"> 52</a>
<a target=_blank id="L53" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L53" rel="#L53" style="text-decoration: none; color: rgb(12, 137, 207);"> 53</a>
<a target=_blank id="L54" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L54" rel="#L54" style="text-decoration: none; color: rgb(12, 137, 207);"> 54</a>
<a target=_blank id="L55" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L55" rel="#L55" style="text-decoration: none; color: rgb(12, 137, 207);"> 55</a>
<a target=_blank id="L56" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L56" rel="#L56" style="text-decoration: none; color: rgb(12, 137, 207);"> 56</a>
<a target=_blank id="L57" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L57" rel="#L57" style="text-decoration: none; color: rgb(12, 137, 207);"> 57</a>
<a target=_blank id="L58" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L58" rel="#L58" style="text-decoration: none; color: rgb(12, 137, 207);"> 58</a>
<a target=_blank id="L59" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L59" rel="#L59" style="text-decoration: none; color: rgb(12, 137, 207);"> 59</a>
<a target=_blank id="L60" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L60" rel="#L60" style="text-decoration: none; color: rgb(12, 137, 207);"> 60</a>
<a target=_blank id="L61" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L61" rel="#L61" style="text-decoration: none; color: rgb(12, 137, 207);"> 61</a>
<a target=_blank id="L62" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L62" rel="#L62" style="text-decoration: none; color: rgb(12, 137, 207);"> 62</a>
<a target=_blank id="L63" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L63" rel="#L63" style="text-decoration: none; color: rgb(12, 137, 207);"> 63</a>
<a target=_blank id="L64" href="http://blog.csdn.net/nugongahou110/article/details/46780135#L64" rel="#L64" style="text-decoration: none; color: rgb(12, 137, 207);"> 64</a>
           
           
public class MainActivity extends Activity {
private Button btShare ;
private Context mContext ;
private Button btWeixin ;
private Button btWeibo ;
private Button btPengyouquan ;
@Override
protected void onCreate ( Bundle savedInstanceState ) {
super . onCreate ( savedInstanceState );
setContentView ( R . layout . activity_main );
mContext = MainActivity . this ;
btShare = ( Button ) findViewById ( R . id . share );
btShare . setOnClickListener ( new View . OnClickListener () {
@Override
public void onClick ( View v ) {
final Dialog dialog = new Dialog ( mContext , R . style . Theme_Light_Dialog );
View dialogView = LayoutInflater . from ( mContext ). inflate ( R . layout . my_dialog , null );
//获得dialog的window窗口
Window window = dialog . getWindow ();
//设置dialog在屏幕底部
window . setGravity ( Gravity . BOTTOM );
//设置dialog弹出时的动画效果,从屏幕底部向上弹出
window . setWindowAnimations ( R . style . dialogStyle );
window . getDecorView (). setPadding ( 0 , 0 , 0 , 0 );
//获得window窗口的属性
android . view . WindowManager . LayoutParams lp = window . getAttributes ();
//设置窗口宽度为充满全屏
lp . width = WindowManager . LayoutParams . MATCH_PARENT ;
//设置窗口高度为包裹内容
lp . height = WindowManager . LayoutParams . WRAP_CONTENT ;
//将设置好的属性set回去
window . setAttributes ( lp );
//将自定义布局加载到dialog上
dialog . setContentView ( dialogView );
btWeixin = ( Button ) dialogView . findViewById ( R . id . bt_weixin );
btWeibo = ( Button ) dialogView . findViewById ( R . id . bt_weibo );
btPengyouquan = ( Button ) dialogView . findViewById ( R . id . bt_pengyouquan );
dialog . show ();
btWeixin . setOnClickListener ( new View . OnClickListener () {
@Override
public void onClick ( View v ) {
Toast . makeText ( mContext , "分享到微信" , Toast . LENGTH_SHORT ). show ();
}
});
btWeibo . setOnClickListener ( new View . OnClickListener () {
@Override
public void onClick ( View v ) {
Toast . makeText ( mContext , "分享到微博" , Toast . LENGTH_SHORT ). show ();
}
});
btPengyouquan . setOnClickListener ( new View . OnClickListener () {
@Override
public void onClick ( View v ) {
Toast . makeText ( mContext , "分享到朋友圈" , Toast . LENGTH_SHORT ). show ();
}
});
}
});
}
}
 来自CODE的代码片
MainActivity.java


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值