如何修复操作栏?更新


  • 更新:我想出了答案,但我的排名太低,无法分享我的答案。

我有一个简单的笔记应用程序,我在滚动和操作栏时遇到问题。我希望操作栏在整个过程中都得到修复(查看),即使我向下滚动笔记或想要复制和粘贴时也是如此。

这是我到目前为止的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<EditText
    android:id="@+id/noteText"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:ems="7" 
    android:singleLine="false"
    android:gravity="top"
    android:lineSpacingExtra="7dp"
    android:inputType="textMultiLine|textCapSentences|textAutoCorrect" >

    <requestFocus />
 </EditText>   
</RelativeLayout>

以下是 Java 代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_note_editor);
    Intent intent = this.getIntent();
    note = new Noteitem();
    note.setKey(intent.getStringExtra("key"));
    note.setText(intent.getStringExtra("text"));
    EditText et = (EditText) findViewById(R.id.noteText);
    et.setText(note.getText());
    et.setSelection(note.getText().length());
I figured out the answer. 

我不得不将滚动视图添加到笔记应用程序中。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_note_editor);
    Intent intent = this.getIntent();
    note = new Noteitem();
    note.setKey(intent.getStringExtra("key"));
    note.setText(intent.getStringExtra("text"));
    EditText et = (EditText) findViewById(R.id.noteText);
    et.setText(note.getText());
    et.setSelection(note.getText().length());
    ScrollView scrollable_contents = (ScrollView) findViewById(R.id.text_view);
    getLayoutInflater().inflate(R.layout.activity_note_editor, scrollable_contents);
}
听起来您需要

向EditText元素添加垂直滚动条。

添加这个:

android:scrollbars="vertical"

所以完整的元素将看起来像:

<EditText
android:id="@+id/noteText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:ems="7" 
android:singleLine="false"
android:gravity="top"
android:lineSpacingExtra="7dp"
android:scrollbars="vertical"
android:inputType="textMultiLine|textCapSentences|textAutoCorrect" >

最新更新