Force FullScreen on EditText in Android

自作多情 提交于 2019-11-29 02:03:21
skv

I solved this issue, not really solved, but found a valid work-around.

The workaround is that I designed a text editor (which looks similar to the fullscreen UI) and on click of each of those EditBoxes the new UI activity is triggerred (with the startActivityForResult() so that once they are completed control is handed back to the calling activity) and after completion of edit the text is transferred back into the main screen.

I also ensured that those boxes which transfer the control do not take focus so that they immediately transfer control to the new UI.

This way I have been able to implement a cancel button, which now actually allows the user to go back without saving the changes he accidentally makes.

I am open to new ideas, but this has worked for me.

Code in Activity:

public void onBtnClicked(View v) {
    EditText current_text_box = (EditText) v;

    Intent intent = new Intent(ObservationActivity.this,
            TexteditorActivity.class);
    intent.putExtra("start_text", current_text_box.getText().toString());
    intent.putExtra("start_position", current_text_box.getSelectionStart());
    startActivityForResult(intent, v.getId());
} 

Code in XML:

<EditText
    android:id="@+id/observation_text"
    style="@style/icon_text"
    android:focusable="false"
    android:imeOptions="flagNoExtractUi"
    android:inputType="textMultiLine"
    android:onClick="onBtnClicked" >
</EditText>

To create the full screen UI I used code, you can use any like (http://android-richtexteditor.googlecode.com/)

You Can Try This

yourEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if(hasFocus){
                yourEditText.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            }
        }
    });

Import LayoutParams of your Parent Layout. Your answer will also work well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!