无法在弹出活动中编辑EditText

时间:2019-02-19 12:43:43

标签: android android-edittext popup

我正在使用Popup Activity(这是通过 android:theme =“ @ android:style / Theme.Dialog” 扩展Activity的Activity)。它包含“编辑”文本,但不可编辑。

所有类似的问题都是关于弹出窗口而不是弹出活动,它们在这里不起作用

这是活动

public class BugActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_bug);
        EditText title = (EditText) findViewById(R.id.bug_subject);
        title.setFocusable(true);
        title.setText("");
        EditText content = (EditText) findViewById(R.id.bug_content);
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        int wi = dm.widthPixels;
        int hi = dm.heightPixels;
        getWindow().setLayout((int) (wi * .84), (int) (hi * .8));
    }

    @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();

        View view = getWindow().getDecorView();
        WindowManager.LayoutParams lp = (WindowManager.LayoutParams) view.getLayoutParams();
        lp.gravity = Gravity.CENTER | Gravity.TOP;
        lp.y = 10;

        getWindowManager().updateViewLayout(view, lp);
    }
}

这是布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:id="@+id/activity_bug"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="zxc.laitooo.mangareader.BugActivity">



    <EditText
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:textColor="@color/manga_white"
        android:gravity="start"
        android:inputType="text"
        android:maxLines="1"
        android:id="@+id/bug_subject"
        android:layout_marginLeft="10dp"
        android:layout_marginStart="10dp"
        android:background="@drawable/rounded_bug_content"
        android:layout_marginRight="10dp"
        android:layout_marginEnd="10dp"
        android:padding="10dp"
        android:layout_marginTop="10dp"
        android:textSize="17dp">

        <requestFocus/>
    </EditText>


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/manga_bug_text"
        android:gravity="start"
        android:text="@string/message"
        android:layout_marginLeft="10dp"
        android:layout_marginStart="10dp"
        android:layout_marginTop="10dp"
        android:textSize="16dp"/>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:textColor="@color/manga_white"
        android:inputType="text"
        android:gravity="start"
        android:id="@+id/bug_content"
        android:layout_marginLeft="10dp"
        android:layout_marginStart="10dp"
        android:background="@drawable/rounded_bug_content"
        android:layout_marginRight="10dp"
        android:layout_marginEnd="10dp"
        android:padding="10dp"
        android:layout_marginTop="10dp"
        android:textSize="17dp">

        <requestFocus/>

    </EditText>

</LinearLayout>

我尝试使用 requestFocus setFocusable(),但仍然无法正常工作

0 个答案:

没有答案