当前位置: 移动技术网 > IT编程>移动开发>Android > Android开发实现模仿微信小窗口功能【Dialog对话框风格窗口】

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

2019年07月23日  | 移动技术网IT编程  | 我要评论

吸血鬼日记第三季下载,征服地带,笔记本性价比排名

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

运用方法:

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

具体效果:

具体实现:

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

<?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>

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

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 中设置 活的的样式为对话框风格

具体如下:

  <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程序设计有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网