本文实例讲述了android开发实现模仿微信小窗口功能。分享给大家供大家参考,具体如下:
运用方法:
将显示窗口的风格 设置为对话框风格即可
具体效果:
具体实现:
首先我们先定义布局文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
<?xml version= "1.0" encoding= "utf-8" ?> <relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" android:id= "@+id/idtatabhost" android:layout_width= "300dp" android:layout_height= "500dp" android:layout_gravity= "center" android:layout_weight= "1" > <imageview android:layout_width= "match_parent" android:layout_height= "match_parent" android:src= "@drawable/wechat" android:scaletype= "fitxy" /> <textview android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:text= "假的 wechat" android:textsize= "20dp" android:textcolor= "#ffffffff" /> <button android:id= "@+id/send" android:onclick= "send" android:text= "点我一下 有惊喜(吓) 。。。" android:textcolor= "#ffffffff" android:layout_width= "match_parent" android:layout_height= "wrap_content" android:layout_alignparentbottom= "true" /> </relativelayout> |
然后我再活动中照常设置监听事件等方法:
1
2
3
4
5
6
7
8
9
10
|
public class mainactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super .oncreate(savedinstancestate); setcontentview(r.layout.activity_main); } public void send(view source){ finish(); } } |
最重要的部分:
在未见的 mainfest.xml 中设置 活的的样式为对话框风格
具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
<application android:allowbackup= "true" android:icon= "@mipmap/ic_launcher" android:label= "@string/app_name" android:roundicon= "@mipmap/ic_launcher_round" android:supportsrtl= "true" android:theme= "@style/apptheme" > <activity android:name= ".mainactivity" android:label= "@string/app_name" android:theme= "@android:style/theme.material.dialog" tools:targetapi= "lollipop" > <intent-filter> <action android:name= "android.intent.action.main" /> <category android:name= "android.intent.category.launcher" /> </intent-filter> </activity> </application> |
大功告成!
希望本文所述对大家android程序设计有所帮助。
原文链接:https://blog.csdn.net/qq_43377749/article/details/85037821