android 开发 短信 气泡,Android Q之气泡弹窗的实现示例

// 创建气泡intent

Intent target = new Intent(mContext, BubbleActivity.class);

PendingIntent bubbleIntent =

PendingIntent.getActivity(mContext, 0, target, 0 /* flags */);

// 创建气泡元数据

Notification.BubbleMetadata bubbleData =

new Notification.BubbleMetadata.Builder()

.setDesiredHeight(600)

// Note: although you can set the icon is not displayed in Q Beta 2

.setIcon(Icon.createWithResource(context, R.drawable.icon))

.setIntent(bubbleIntent)

.build();

// 创建通知

Person chatBot = new Person.Builder()

.setBot(true)

.setName("BubbleBot")

.setImportant(true)

.build();

Notification.Builder builder =

new Notification.Builder(mContext, CHANNEL_ID)

.setContentIntent(contentIntent)

.setSmallIcon(smallIcon)

.setBubbleMetadata(bubbleData);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 Android实现尖角气泡,可以使用 Shape Drawable 和 Layer List Drawable。 首先,创建一个 Shape Drawable 来绘制气泡的形状,设置一个圆角和一条尖角线段。这里是一个示例代码: ```xml <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@android:color/white" /> <corners android:radius="8dp" /> <stroke android:width="1dp" android:color="#CCCCCC" /> <padding android:left="8dp" android:top="8dp" android:right="8dp" android:bottom="16dp" /> <size android:width="120dp" android:height="56dp" /> <stroke android:width="2dp" android:color="#000000" /> <rotate android:fromDegrees="45" android:pivotX="50%" android:pivotY="-50%"> <shape android:shape="line"> <stroke android:width="2dp" android:color="#000000" /> <size android:width="16dp" android:height="16dp" /> </shape> </rotate> </shape> ``` 然后,把这个 Shape Drawable 放到一个 Layer List Drawable 中,以便在气泡上方放置一些文本或图像。这里是一个示例代码: ```xml <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <solid android:color="@android:color/transparent" /> <size android:width="120dp" android:height="56dp" /> </shape> </item> <item> <shape android:shape="rectangle"> <solid android:color="@android:color/white" /> <corners android:radius="8dp" /> </shape> </item> <item android:gravity="top|center_horizontal"> <bitmap android:src="@drawable/ic_launcher" android:gravity="center" /> </item> </layer-list> ``` 最后,在布局文件中使用这个 Layer List Drawable,设置气泡的位置和大小。这里是一个示例代码: ```xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/bubble" android:layout_alignParentRight="true" android:layout_marginRight="16dp" android:layout_marginTop="16dp" /> </RelativeLayout> ``` 运行应用程序,你会看到一个带有尖角的气泡在屏幕上。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值