检查Commonsware是否正确实施了CWAC-RichEdit库

时间:2014-09-09 05:02:48

标签: android commonsware-cwac

我正在为我的第一个应用程序开发一个模块,用于为用户提供笔记功能。 CWAC库是一个宝贵的资源和工具,用于克服我在理解如何格式化文本方面的挑战。

我已经设法将其作为Android Studio中的项目导入,并按照说明如何在发布的自述文件部分中实现此库:https://github.com/commonsguy/cwac-richedit

以下是我的Notetaking活动类的布局:

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

    tools:context="com.example.hotel.moeccefamilytime.ReflectionNotes">

    <com.commonsware.cwac.richedit.RichEditText
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/editor"
        android:gravity="top|left"
        android:inputType="textMultiLine"
        android:imeOptions="flagNoExtractUi"/>
    <requestFocus/>

</RelativeLayout>

接下来,这是活动源类:

public class ReflectionNotes extends Activity{

    RichEditText rEdit;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_reflection_notes);

        rEdit= (RichEditText)findViewById(R.id.editor);
        rEdit= new RichEditText(getApplicationContext());
        checkText(rEdit.getText().toString());

       // rEdit.setOnSelectionChangedListener(this);
    }

   /* public void onSelectionChanged(int start,int end,List <Effect<?>> list){

    }*/

    public void checkText(String m){
        if(m.length()>0){
            rEdit.enableActionModes(true);
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.reflection_notes, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

我也尝试过使用setOnItemSelectedListener,但是当输入的任何文本突出显示时,没有显示任何格式化选项(只显示默认的复制,粘贴,刻度图标)。

我对编程的经验不足使得这个问题听起来微不足道,但是我希望专家程序员和开发人员能够帮助我提供建议。再次感谢。

1 个答案:

答案 0 :(得分:0)

删除:

rEdit= new RichEditText(getApplicationContext());

并且,由于您似乎没有调用checkText(),因此在通过rEdit.enableActionModes(true)检索onCreate()后,将rEdit移至findViewById()