Android-skin-support icon indicating copy to clipboard operation
Android-skin-support copied to clipboard

WindowManager添加EditText,EditText无焦点,不能唤起输入法

Open zff0123 opened this issue 4 years ago • 7 comments

package com.ximsfei.skindemo.window;

import android.app.Service; import android.content.Context; import android.content.Intent; import android.graphics.PixelFormat; import android.net.wifi.WifiManager; import android.os.Build; import android.os.IBinder; import android.view.LayoutInflater; import android.view.View; import android.view.WindowManager; import android.widget.EditText; import android.widget.TextView;

import com.ximsfei.skindemo.R;

public class WindowService extends Service implements View.OnClickListener {

private WindowManager wManager;
private WindowManager.LayoutParams mParams;
//private TextView textView;
private EditText editText;
private boolean flag = true;

@Override
public IBinder onBind(Intent intent) {
    return null;
}

@Override
public void onCreate() {
    wManager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
    mParams = new WindowManager.LayoutParams();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        mParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
    } else {
        mParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
    }
    mParams.format = PixelFormat.TRANSLUCENT;
    //mParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
    mParams.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
    mParams.width = 490;
    mParams.height = 160;
    mParams.x = 0;
    mParams.y = 0;
    //textView = (TextView) LayoutInflater.from(getApplicationContext()).inflate(R.layout.item_t, null);
    //textView.setText("WindowManager add View");
    //textView.setOnClickListener(this);
    editText = (EditText) LayoutInflater.from(getApplicationContext()).inflate(R.layout.item_editor, null);
    editText.setText("WindowManager add EditText");
    super.onCreate();
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (flag) {
        flag = false;
        //wManager.addView(textView, mParams);
        wManager.addView(editText, mParams);
    }
    return super.onStartCommand(intent, flags, startId);
}

@Override
public void onDestroy() {

// if (textView.getParent() != null) { // wManager.removeView(textView); // } if (editText.getParent() != null) { wManager.removeView(editText); } super.onDestroy(); }

@Override
public void onClick(View v) {

// if (v.equals(textView)) { // flag = true; // if (textView.getParent() != null) { // wManager.removeView(textView); // } // } if (v.equals(editText)) { flag = true; if (editText.getParent() != null) { editText.requestFocus(); //wManager.removeView(textView); } } } }

<EditText xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="@color/t2_6_background" android:gravity="center" android:orientation="vertical" android:focusable="true" android:textColor="@color/text_color" />

zff0123 avatar Jul 03 '20 12:07 zff0123

应该是主题的问题,检查下主题

ximsfei avatar Jul 03 '20 13:07 ximsfei

是说检查Application的主题? 上面的问题我是直接在你的Project中demo / skin-androidx-app / com.ximsfei.skindemo.window.WindowService 类中测试的。 而 demo / skin-androidx-app / com.ximsfei.skindemo.tab.fragment.FirstFragment 中的EditText是可以正常获取焦点和弹出键盘的。

什么样的主题设置对EditText的焦点获取有影响,还是弄不太清楚。还望楼主指正,感谢!

zff0123 avatar Jul 04 '20 08:07 zff0123

是说检查Application的主题? 上面的问题我是直接在你的Project中demo / skin-androidx-app / com.ximsfei.skindemo.window.WindowService 类中测试的。 而 demo / skin-androidx-app / com.ximsfei.skindemo.tab.fragment.FirstFragment 中的EditText是可以正常获取焦点和弹出键盘的。

什么样的主题设置对EditText的焦点获取有影响,还是弄不太清楚。还望楼主指正,感谢!

同问,解决了没有....

youjinhua avatar Jul 09 '20 08:07 youjinhua

应该是主题的问题,检查下主题

在application加了皮肤框架,某些地方的check点击无反应,edittext也弹不出,请问下是什么原因。去掉皮肤框架就又好了

youjinhua avatar Jul 09 '20 08:07 youjinhua

是说检查Application的主题? 上面的问题我是直接在你的Project中demo / skin-androidx-app / com.ximsfei.skindemo.window.WindowService 类中测试的。 而 demo / skin-androidx-app / com.ximsfei.skindemo.tab.fragment.FirstFragment 中的EditText是可以正常获取焦点和弹出键盘的。 什么样的主题设置对EditText的焦点获取有影响,还是弄不太清楚。还望楼主指正,感谢!

同问,解决了没有....

还没有

zff0123 avatar Jul 27 '20 14:07 zff0123

应该是主题的问题,检查下主题

在application加了皮肤框架,某些地方的check点击无反应,edittext也弹不出,请问下是什么原因。去掉皮肤框架就又好了

check点击无法反映可以设置 android:clickable="true" 解决。

zff0123 avatar Aug 05 '20 06:08 zff0123

发生原因是主题没有用Theme.AppCompat,如果第三方改不了主题可以使用SkinCompatManager.setSkinAllActivityEnable(false),这个默认值是true还是挺让人意外的。

hazyrain avatar Aug 12 '21 12:08 hazyrain