服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - Android - Android开发实现模仿微信小窗口功能【Dialog对话框风格窗口】

Android开发实现模仿微信小窗口功能【Dialog对话框风格窗口】

2022-09-29 17:13水中鱼之1999 Android

这篇文章主要介绍了Android开发实现模仿微信小窗口功能,结合实例形式分析了Android实现微信风格Dialog对话框窗口相关功能与布局操作技巧,需要的朋友可以参考下

本文实例讲述了android开发实现模仿微信小窗口功能。分享给大家供大家参考,具体如下:

运用方法:

将显示窗口的风格 设置为对话框风格即可

具体效果:

Android开发实现模仿微信小窗口功能【Dialog对话框风格窗口】

具体实现:

首先我们先定义布局文件:

?
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

延伸 · 阅读

精彩推荐