Я разрабатываю модуль в своем первом приложении для создания заметок для пользователей. Библиотека CWAC была ценным ресурсом и инструментом для преодоления моих проблем с пониманием того, как форматировать текст.
Мне удалось импортировать его как проект в Android Studio и следовать инструкциям по реализации этой библиотеки в разделе ReadMe: 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, но, однако, когда любой введенный текст выделяется, параметры форматирования не отображаются (как обычно отображаются только значок копирования, вставки, галочки по умолчанию).
Из-за моего неопытности в программировании этот вопрос может показаться тривиальным, однако я был бы признателен за помощь опытных программистов и разработчиков в этом вопросе. Еще раз спасибо.