3
  1. I create popup window in service like this

    public class ChatService extends Service {
        WindowManager mWindowMgr;
        WindowManager.LayoutParams mWinMgrParam;
        View mView;
    
        @Override
        public void onCreate()
        {
            LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
            mView = inflater.inflate(R.layout.chat_window, null);
    
            mWinMgrParam = new WindowManager.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_PHONE;,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            PixelFormat.TRANSLUCENT);
    
            mWindowMgr = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
            mWindowMgr.addView(mView, mWinMgrParam);
        }
    
    }
    
  2. But not open copy&paste context view in edittext and textview like this. please see this attachment img. string was selected but not popup "copy, paste" context view...

enter image description here

  1. I want to show copy and paste popup in my service view. How to do that?

  2. chat_service.xml

    <TextView
        android:id="@+id/tvContents"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@color/black_overlay_150"
        android:maxLines="50"
        android:scrollbars="vertical"
        android:textColor="@color/white"
        android:textIsSelectable="true" />
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="@color/green_light">
    
        <TextView
            android:id="@+id/tvNickName"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="center_vertical"
            android:text="nickname"
            android:textSize="14sp" />
    
        <EditText
            android:id="@+id/etUserInput"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:selectAllOnFocus="true"
            android:singleLine="true"
            android:textSize="14sp" />
    
  3. AndroidManifest.xml

<service
    android:permission="android.permission.SYSTEM_ALERT_WINDOW"
    android:enabled="true"
    android:name=".talk.ChatService">
</service>
L Y E S - C H I O U K H
  • 4,765
  • 8
  • 40
  • 57

1 Answers1

0

Change in layout file chat_window.xml: add below property to your EditText

android:textIsSelectable="true"

Vikasdeep Singh
  • 20,983
  • 15
  • 78
  • 104