前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Android开发实现模仿微信小窗口功能【Dialog对话框风格窗口】

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

作者头像
砸漏
发布2020-11-04 09:52:41
9950
发布2020-11-04 09:52:41
举报
文章被收录于专栏:恩蓝脚本

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

运用方法:

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

具体效果:

具体实现:

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

代码语言:javascript
复制
<?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 

然后我再活动中照常设置监听事件等方法:

代码语言:javascript
复制
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 中设置 活的的样式为对话框风格

具体如下:

代码语言:javascript
复制
  <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相关内容感兴趣的读者可查看本站专题:《Android开发入门与进阶教程》、《Android调试技巧与常见问题解决方法汇总》、《Android基本组件用法总结》、《Android视图View技巧总结》、《Android布局layout技巧总结》及《Android控件用法总结》

希望本文所述对大家Android程序设计有所帮助。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-09-11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档