我需要在Activity
我的EditText
readonly
模式的开头,所以我这样做,如下所示:
xml
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:paddingBottom="@dimen/edge_offset"
android:paddingLeft="@dimen/edge_offset"
android:paddingStart="@dimen/edge_offset"
android:paddingRight="@dimen/edge_offset"
android:paddingEnd="@dimen/edge_offset"
android:paddingTop="@dimen/edge_offset"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<EditText
android:id="@+id/hometask_edt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="textMultiLine"
android:gravity="top|start"
android:scrollHorizontally="false"
android:hint="@string/label_summary"/>
</android.support.design.widget.TextInputLayout>
</android.support.design.widget.CoordinatorLayout>
</layout>
活动
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBinder = DataBindingUtil.setContentView(this, R.layout.activity_hometask);
// Setup EditText
mBinder.hometaskEdt.setInputType(InputType.TYPE_NULL);
}
当用户点击菜单项时,EditText
必须再次可编辑。我试着这样做:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
if (itemId == R.id.action_edit) {
mBinder.hometaskEdt.setInputType(InputType.TYPE_CLASS_TEXT);
mBinder.hometaskEdt.invalidate();
return true;
}
return super.onOptionsItemSelected(item);
}
但是,当然,它不起作用=(我做错了什么?
答案 0 :(得分:-1)