1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| private TextListener editerListener;
private KeyListener keyListener;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
slider= (Slider) findViewById(R.id.slider);
toHide=(RelativeLayout) findViewById(R.id.toHide);
slider.setToHide(toHide);
cacherListener= new CacherListener();
styleListener= new StyleListener();
couleurListener = new CouleurListener();
editerListener = new TextListener();
keyListener = new KeyListener();
cacher=(Button) findViewById(R.id.cacher);
cacher.setOnClickListener(cacherListener);
gras = (Button) findViewById(R.id.bGras);
gras.setOnClickListener(styleListener);
italique = (Button) findViewById(R.id.bItal);
italique.setOnClickListener(styleListener);
souligne = (Button) findViewById(R.id.bSoul);
souligne.setOnClickListener(styleListener);
couleur = (RadioGroup) findViewById(R.id.couleur);
couleur.setOnCheckedChangeListener(couleurListener);
editer=(EditText) findViewById(R.id.editer);
editer.setOnKeyListener(keyListener);
editer.addTextChangedListener(editerListener);
text = (TextView) findViewById(R.id.text);
}
....
private class TextListener implements TextWatcher {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
text.setText(Html.fromHtml("<font color =\""+currentColor+"\">"+editer.getText().toString()));
Toast toast = Toast.makeText(getApplicationContext(), "text", Toast.LENGTH_LONG);
toast.show();
}
public void afterTextChanged(Editable s) {
}
};
private class KeyListener implements View.OnKeyListener{
public boolean onKey(View v, int keyCode, KeyEvent event) {
int start = editer.getSelectionStart();
Toast toast = Toast.makeText(getApplicationContext(), "ok", Toast.LENGTH_LONG);
toast.show();
if(event.getAction()==0)
if(keyCode==66)
editer.getText().insert(start, "<br />");
return true;
}
};
} |
Partager