私聊改造:长按弹窗UI修改
This commit is contained in:
5
nim_uikit/res/drawable/nim_shape_767676_8dp.xml
Normal file
5
nim_uikit/res/drawable/nim_shape_767676_8dp.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="#767676" />
|
||||
<corners android:radius="8dp" />
|
||||
</shape>
|
10
nim_uikit/res/layout/nim_custom_popup_window.xml
Normal file
10
nim_uikit/res/layout/nim_custom_popup_window.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/ll_root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:background="@drawable/nim_shape_767676_8dp"
|
||||
android:orientation="vertical" >
|
||||
|
||||
</LinearLayout>
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,75 @@
|
||||
package com.netease.nim.uikit.common.ui.dialog;
|
||||
|
||||
import static android.widget.LinearLayout.SHOW_DIVIDER_BEGINNING;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.util.Pair;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.netease.nim.uikit.R;
|
||||
import com.netease.nim.uikit.common.util.sys.ScreenUtil;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class CustomPopupWindow extends PopupWindow {
|
||||
|
||||
private final Context context;
|
||||
private final LinearLayout llRoot;
|
||||
private final List<Pair<String, View.OnClickListener>> itemTextList = new LinkedList<>();
|
||||
private int orientation;
|
||||
|
||||
public CustomPopupWindow(Context context, int orientation) {
|
||||
this.context = context;
|
||||
this.orientation = orientation;
|
||||
llRoot = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.nim_custom_popup_window, null);
|
||||
setContentView(llRoot);
|
||||
llRoot.setShowDividers(SHOW_DIVIDER_BEGINNING);
|
||||
llRoot.setOrientation(orientation);
|
||||
setBackgroundDrawable(new ColorDrawable());
|
||||
setOutsideTouchable(true);
|
||||
setFocusable(true);
|
||||
}
|
||||
|
||||
public void addItem(String itemText, View.OnClickListener listener) {
|
||||
itemTextList.add(new Pair<>(itemText, listener));
|
||||
}
|
||||
|
||||
public void show(View anchor, int xoff, int yoff) {
|
||||
for (Pair<String, View.OnClickListener> pair : itemTextList) {
|
||||
llRoot.addView(
|
||||
createTextView(pair.first, pair.second),
|
||||
new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, ScreenUtil.dip2px(30))
|
||||
);
|
||||
}
|
||||
setHeight(ScreenUtil.dip2px(30 * (orientation == LinearLayout.HORIZONTAL ? 1 : itemTextList.size())));
|
||||
setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
|
||||
showAsDropDown(anchor, xoff, yoff);
|
||||
}
|
||||
|
||||
private TextView createTextView(CharSequence text, View.OnClickListener listener) {
|
||||
TextView textView = new TextView(context);
|
||||
textView.setPadding(ScreenUtil.dip2px(8), 0, ScreenUtil.dip2px(8), 0);
|
||||
textView.setGravity(Gravity.CENTER);
|
||||
textView.setTextColor(Color.WHITE);
|
||||
textView.setTextSize(10);
|
||||
textView.setSingleLine(true);
|
||||
textView.setOnClickListener(v -> {
|
||||
listener.onClick(v);
|
||||
dismiss();
|
||||
});
|
||||
textView.setText(text);
|
||||
return textView;
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user