【发布时间】: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,但是当输入的任何文本被突出显示时,没有显示格式选项(只显示默认的复制、粘贴、勾选图标)。
我对编程的缺乏经验使这个问题听起来微不足道,但是我希望专家程序员和开发人员能够帮助我就此提供建议。再次感谢。
【问题讨论】: