Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String text = exercicios.get(0).getPergunta();
- Log.i(TAG, exercicios.get(0).getPergunta());
- //String text = "texto # texto";
- //Posição onde colocar a imegem(posição da marca)
- int imagePos = text.indexOf("#");
- //Criar um SpannableString do texto
- SpannableString spannableString = new SpannableString(text);
- //Obter o drawable a inserir
- Drawable drawable = getResources().getDrawable(R.drawable.shapepergunta);
- drawable.setBounds(0, 0,drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight());
- //Criar um ImageSpan do drawable
- ImageSpan imageSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
- //Inserir a imagem(ImageSpan) no texto(SpannableString)
- spannableString.setSpan(imageSpan,imagePos,imagePos+1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
- //Atribuir o texto com a imagem ao TextView
- txvpergunta.setText(spannableString);
Add Comment
Please, Sign In to add comment