栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Android-气泡对话框(根据被点击View位置显示、可定制,androidkotlin面试题

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android-气泡对话框(根据被点击View位置显示、可定制,androidkotlin面试题

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-nZ8Fmmpi-1636559775978)(https://user-gold-cdn.xitu.io/2017/12/15/1605834810534ae1?imageView2/0/w/1280/h/960/ignore-error/1)]

new BubbleDialog(this)
.addContentView(LayoutInflater.from(this).inflate(R.layout.dialog_view3, null))
.setClickedView(mButton4)
.setPosition(mPosition)
.setOffsetY(8)
.calBar(true)
.show();

当想要输入框随软键盘上移时

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-QCxh6DTW-1636559776003)(https://user-gold-cdn.xitu.io/2017/12/15/1605834e7b27a92d?imageslim)]

new BubbleDialog(this)
.addContentView(LayoutInflater.from(this).inflate(R.layout.dialog_view, null))
.setClickedView(mButton12)
.setPosition(mPosition)
.calBar(true)
.softShowUp()
.show();

自定义 BubbleLayout.

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-OK26OQLy-1636559776004)(https://user-gold-cdn.xitu.io/2017/12/15/160583536559639f?imageView2/0/w/1280/h/960/ignore-error/1)]

BubbleLayout bl = new BubbleLayout(this);
bl.setBubbleColor(Color.BLUE);
bl.setShadowColor(Color.RED);
bl.setLookLength(Util.dpToPx(this, 54));
bl.setLookWidth(Util.dpToPx(this, 48));
new BubbleDialog(this)
.addContentView(LayoutInflater.from(this).inflate(R.layout.dialog_view5, null))
.setClickedView(mButton8)
.setPosition(mPosition)
.calBar(true)
.setBubbleLayout(bl)
.show();

自定义 BubbleDialog,可交互的 BubbleDialog.

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-YpohvkxU-1636559776005)(https://user-gold-cdn.xitu.io/2017/12/15/1605835b168088f0?imageslim)]

1、布局

and

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

浏览器打开:qq.cn.hn/FTe 免费领取

roid:id="@+id/button13"
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:text=“Button1” />

2、自定义 BubbleDialog

public class CustomOperateDialog extends BubbleDialog implements View.onClickListener {
private ViewHolder mViewHolder;
private onClickCustomButtonListener mListener;

public CustomOperateDialog(Context context) {
super(context);
calBar(true);
setTransParentBackground();
setPosition(Position.TOP);
View rootView = LayoutInflater.from(context).inflate(R.layout.dialog_view4, null);
mViewHolder = new ViewHolder(rootView);
addContentView(rootView);
mViewHolder.btn13.setonClickListener(this);
mViewHolder.btn14.setonClickListener(this);
mViewHolder.btn15.setonClickListener(this);
}

@Override
public void onClick(View v) {
if (mListener != null)
{
mListener.onClick(((Button)v).getText().toString());
}
}

private static class ViewHolder {
Button btn13, btn14, btn15;
public ViewHolder(View rootView) {
btn13 = rootView.findViewById(R.id.button13);
btn14 = rootView.findViewById(R.id.button14);
btn15 = rootView.findViewById(R.id.button15);
}
}

public void setClickListener(onClickCustomButtonListener l) {
this.mListener = l;
}

public interface onClickCustomButtonListener {
void onClick(String str);
}
}

3、显示

CustomOperateDialog codDialog = new CustomOperateDialog(this)
.setPosition(mPosition)
.setClickedView(mButton10);
codDialog.setClickListener(new CustomOperateDialog.onClickCustomButtonListener()
{
@Override
public void onClick(String str) {
mButton10.setText(“点击了:” + str);
}
});
codDialog.show();

查看关于BappyDialog的使用代码

TestDialogActivity 代码

写法建议

根据@hm该朋友在文章中反馈的多次点击后位置不对的问题,是由于多次对BappyDialog进行了设置导致,所以建议下方写法。(当然如果对重复调用setClickedView()方法设置不同的被点击的控件来更新位置有需要,是需要写在外面的。)

if(mBubbleDialog == null)
{
mBubbleDialog = new BubbleDialog(this)
.addContentView(LayoutInflater.from(this).inflate(R.layout.dialog_view3, null))
.setClickedView(mButton4)
.setPosition(mPosition)
.setOffsetY(8)
.calBar(true);
}
mBubbleDialog.show();


如何使用 HappyBubble-BubbleLayout? 在XML代码中设置属性值

属性参照表

属性描述
lookAtleft, top, right, bottom箭头指向
lookLengthdimension箭头的长度
lookPositiondimension箭头相对于x或y轴的位置
lookWidthdimension箭头的宽度
bubbleColorcolor气泡的颜色
bubbleRadiusdimension气泡四角的圆弧
bubblePaddingdimension气泡边缘到内容的距离
shadowRadiusdimension阴影的扩散大小
shadowXdimension阴影在x轴方向的偏移
shadowYdimension阴影在y轴方向的偏移
shadowColorcolor阴影的颜色

xml 例子

xmlns:app=“http://schemas.android.com/apk/res-auto”
android:id="@+id/bubbleLayout"
android:layout_width=“match_parent”
android:layout_height=“200dp”
android:layout_margin=“16dp”
app:lookAt=“left”
app:lookLength=“16dp”
app:lookPosition=“20dp”
app:lookWidth=“16dp” />

在java代码中定义属性值。

BubbleLayout 通过“set属性名”方法和invalidate方法来更新BubbleLayout。

mBubbleLayout.setLook(BubbleLayout.Look.LEFT);

查看更多

MainActivity 代码

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-l0ZoGpa4-1636559776006)(https://user-gold-cdn.xitu.io/2017/12/15/1605836ed9cbff27?imageslim)]

Demo 下载 在java代码中定义属性值。

BubbleLayout 通过“set属性名”方法和invalidate方法来更新BubbleLayout。

mBubbleLayout.setLook(BubbleLayout.Look.LEFT);

查看更多

MainActivity 代码

[外链图片转存中…(img-l0ZoGpa4-1636559776006)]

Demo 下载
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/460097.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号