Android solution EditText put into the Popupwindow, the original copy, paste, select all, the failure of the selection function _android

Source: Internet
Author: User


1, the original is EditView put to the Popupwindow, found that EditView original copy, paste, select all, the selection function is invalid, so they replaced with dialogfragment Popupwindow



Directly on the code



①, first look at the layout file


<?xml version="." encoding="utf-"?>
<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="dp"
android:layout_weight=""
android:background="#"
android:alpha="."
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="dp"
android:src="@drawable/popup_comment_no" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
Android: text = "speak"
android:textColor="#"
android:textSize="sp" />
<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="dp"
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="dp"
android:background="#ffffff"
android:gravity="top"
Android: hint = "leave a message here"
android:minLines="" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="dp"
android:layout_marginLeft="dp"
android:layout_marginRight="dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
Android: text = "civilized Internet access"
android:textSize="sp" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>


②, look at the custom diaglogfragment code


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.v.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 ABCD popup; / / Cancel button
Private ImageView IV? Write? Pop; / / confirm button
Private EditText et \ comment \ pop; / / comment content
Private LinearLayout ll? Background? Dialog; / / container
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);
//This code means to make dialogfragment full screen when it pops up
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);
//Make the background of dialogfragment transparent
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
initView(view);
InitEvent ();
Return view;
}
//Initialize 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(){
/ / cancel
iv_quxiao_popup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Dismiss ();
}
};
//Confirm sending
iv_write_popup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (et_comment_popup.getText().toString().length() > ) {
if (!isCommenting) {
isCommenting = true;
} else {
Toast. Maketext (getactivity(), "commenting, please do not repeat", toast. Length_long). Show();
}
} else {
Toast. Maketext (getactivity(), "content cannot be empty", toast. Length_short). Show();
}
}
};
ll_background_dialog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Dismiss ();
}
};
}
}


3. How to use


Fragmentmanager manager = Getsupportfragmentmanager ()//The fragment of V or the customdialogfragment in the app bag
Dialogfragment = new Customdialogfragment (UID, ID, CID);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.