【问题标题】:Check for Correct Implementation of CWAC-RichEdit Library by Commonsware通过 Commonsware 检查 CWAC-RichEdit 库的正确实现
【发布时间】:2014-09-09 05:02:47
【问题描述】:

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

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

这是我的笔记活动类的布局:

<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,但是当输入的任何文本被突出显示时,没有显示格式选项(只显示默认的复制、粘贴、勾选图标)。

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

【问题讨论】:

    标签: android commonsware-cwac


    【解决方案1】:

    删除:

    rEdit= new RichEditText(getApplicationContext());
    

    而且,由于您似乎没有呼叫checkText(),因此在您通过findViewById() 检索到rEdit 后,将rEdit.enableActionModes(true) 移动到onCreate()

    【讨论】:

    • 感谢指正。但是,我一直在尝试不同的方法,但在更正代码后执行时仍会引发以下未定义的类异常: E/AndroidRuntime: FATAL EXCEPTION: main java.lang.NoClassDefFoundError: com.commonsware.cwac.richedit.R$menu在 com.commonsware.cwac.richedit.RichEditText.enableActionModes(RichEditText.java:333)
    • @Learn-veloper:抱歉,但我不知道您可能做了什么来解释该特定症状。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-17
    • 2011-04-16
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    • 2014-07-06
    • 1970-01-01
    相关资源
    最近更新 更多