Android--解决EditText放到popupWindow中,原有复制、粘贴、全选、选择功能失效问题
1、原来是将EditView放到了popupwindow,发现EditView原有的复制、粘贴、全选、选择功能失效了,所以便用DialogFragment代替了popupWindow
直接上代码
①、先看布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:orientation="vertical">
<LinearLayout
android:id="@+id/ll_background_dialog"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#000"
android:alpha="0.7"
android:orientation="horizontal"> </LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffcdcdcd"
android:orientation="vertical"> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"> <ImageView
android:id="@+id/iv_quxiao_popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:src="@drawable/popup_comment_no" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="发言"
android:textColor="#000"
android:textSize="16sp" /> <ImageView
android:id="@+id/iv_write_popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:padding="16dp"
android:src="@drawable/popup_commnet_ok" />
</RelativeLayout> <EditText
android:id="@+id/et_comment_popup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:background="#ffffff"
android:gravity="top"
android:hint="在这里留言"
android:minLines="3" /> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="文明上网"
android:textSize="12sp" />
</RelativeLayout>
</LinearLayout> </ScrollView> </LinearLayout>
②、看自定义diaglogFragment的代码
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.app.Fragment;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast; import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest; import org.json.JSONException;
import org.json.JSONObject; import java.util.HashMap;
import java.util.Map; import newairtek.com.app.AppApplication;
import newairtek.com.sdnewsandroid.R;
import newairtek.com.url.SdNewsUrl; /**
* A simple {@link Fragment} subclass.
*/
@SuppressLint("ValidFragment")
public class CustomDialogFragment extends DialogFragment { private ImageView iv_quxiao_popup;//取消按钮
private ImageView iv_write_popup; //确认按钮
private EditText et_comment_popup;//评论内容
private LinearLayout ll_background_dialog;//容器 private boolean isCommenting = false; private String uid;
private String id;
private String cid; public CustomDialogFragment(String uid, String id, String cid) {
this.uid = uid;
this.id = id;
this.cid = cid;
} @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//这句代码的意思是让dialogFragment弹出时沾满全屏
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Holo_Light_DialogWhenLarge_NoActionBar);
} @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.popup_write_comment, null);
//让DialogFragment的背景为透明
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
initView(view);
initEvent();
return view;
} //初始化view
private void initView(View view) {
iv_quxiao_popup = (ImageView) view.findViewById(R.id.iv_quxiao_popup);
iv_write_popup = (ImageView) view.findViewById(R.id.iv_write_popup);
et_comment_popup = (EditText) view.findViewById(R.id.et_comment_popup);
ll_background_dialog = (LinearLayout) view.findViewById(R.id.ll_background_dialog);
} private void initEvent(){
//取消
iv_quxiao_popup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
}
});
//确认发送
iv_write_popup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (et_comment_popup.getText().toString().length() > 1) {
if (!isCommenting) {
isCommenting = true; } else {
Toast.makeText(getActivity(), "正在评论,请勿重复操作", Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(getActivity(), "内容不能为空", Toast.LENGTH_SHORT).show();
}
}
});
ll_background_dialog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
}
});
} }
3、如何使用
FragmentManager manager = getSupportFragmentManager();//区分是v4的Fragment还是app包里面的
CustomDialogFragment dialogFragment = new CustomDialogFragment(uid, id, cid);
dialogFragment.show(manager, "custom");
效果图

Android--解决EditText放到popupWindow中,原有复制、粘贴、全选、选择功能失效问题的更多相关文章
- VC++6.0/MFC 自定义edit 限制输入内容 响应复制粘贴全选剪切的功能
Ctrl组合键ASCII码 ^Z代表Ctrl+z ASCII值 控制字符 ASCII值 控制字符 ASCII值 控制字符 ASCII值 控制字符0(00) ...
- 【转】MFC 自定义edit 限制输入十六进制内容 响应复制粘贴全选剪切的功能
参考地址:MFC 自定义edit 限制输入内容 响应复制粘贴全选剪切的功能 Ctrl组合键ASCII码 ^Z代表Ctrl+z ASCII值 控制字符 AS ...
- android 长按弹出菜单,复制,粘贴,全选
<!-- 定义基础布局LinearLayout --> <LinearLayout xmlns:android="http://schemas.android.com/ap ...
- js 禁止复制粘贴全选
// 取消右键菜单document.oncontextmenu = function(e){ var t = e || window.event; var elm = t.target || t.sr ...
- Android中的复制粘贴
Android中的复制粘贴 The Clipboard Framework 当使用clipboard framework时,把数据放在一个剪切对象(clip object)里,然后这个对象会放在系统的 ...
- jqueryUI中datepicker的使用,解决与asp.net中的UpdatePanel联合使用时的失效问题
1.jqueryUI的datepicker的使用 -->首先在jqueryUI官网上根据你的需要下载适合你系统主题的样式,jqueryUI主题下载地址: -->下载后的文件 jquery- ...
- 在CMD命令行和PowerShell中实现复制粘贴功能
在CMD命令行和PowerShell中实现复制粘贴功能 常常使用命令行或者PowerShell的朋友肯定会遇到这样的情况:粘贴文本非常easy,右键--选择粘贴就可以,可是想要复制命令 ...
- Oracle SQL Developer 编辑区不能删除,后退,空格,复制粘贴等功能都失效的解决办法
Oracle SQL Developer 编辑区不能删除,后退,空格,复制粘贴等功能都失效的解决办法 解决: 打开菜单并选择Tools-prefrence-Accelerators-Load Pres ...
- ubuntu18.04下取消中键复制粘贴功能
Q: armlinux开发,主机采用ubuntu18.04操作系统,使用过程中关于鼠标中键有如下操作现象, 操作: 1.选中文本, 2.将鼠标光标定位到要插入的位置 3.按下鼠标中键 现象:将自动复制 ...
随机推荐
- 课程一(Neural Networks and Deep Learning),第二周(Basics of Neural Network programming)—— 2、编程作业常见问题与答案(Programming Assignment FAQ)
Please note that when you are working on the programming exercise you will find comments that say &q ...
- 自定义 Scrapy 爬虫请求的 URL
之前使用 scrapy 抓取数据的时候 ,默认是在逻辑中判断是否执行下一次请求 def parse(self): # 获取所有的url,例如获取到urls中 for url in urls: yiel ...
- mycat中间件--linux安装mycat1.6版本
一.mycat安装前准备1.mycat下载地址,点击此处进行下载2.环境要求如下: mycat使用Java开发,因为用到了JDK 7的部分功能,所以在使用前请确保安装了JDK 7.0,并设置了正确的J ...
- 技术笔记2 jetty jboss
jetty热部署: jetty启动加载文件webdefault.xml .文件里: <init-param> <param-name>useFileMappedBuffer&l ...
- 项目复审——Alpha阶段
Deadline: 2018-5-19 10:00PM,以提交至班级博客时间为准. 5.10实验课上,以(1.2班级,3.4班级为单位)进行项目复审.根据以下要求,完成本团队对其他团队的复审排序. 参 ...
- Ant Trip(区别于二分匹配中最小路径覆盖的一笔画问题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3018 题目: Problem Description Ant Country consist of ...
- Java并发编程-闭锁
闭锁是一种同步器 ( Synchronizer ),它可以延迟线程的进度直到线程到达终止状态,CountDownLatch是一个灵活的闭锁实现:1)允许一个或多个线程等待一个事件集的发生,闭锁的状态包 ...
- 乐字节-Java8新特性-接口默认方法
总概 JAVA8 已经发布很久,而且毫无疑问,java8是自java5(2004年发布)之后的最重要的版本.其中包括语言.编译器.库.工具和JVM等诸多方面的新特性. Java8 新特性列表如下: 接 ...
- github小白上传本地代码及更新代码到GitHub及华为云教程
上传本地代码 第一步:去github上创建自己的Repository,创建页面如下图所示: 红框为新建的仓库的https地址 第二步: echo "# Test" >> ...
- 什么是Solr
什么是Solr Lucene复习: 1.什么是lucene:全文检索工具包 2.Lucene的工作原理: 索引数据的创建 从原始文件中提取一些可以用来搜索的数据(封装成各种Field),把各field ...