java - How to add speech bubbles around messages in textview ? Can I use just a text view to initiate a chat interface? -


i relatively amateur coder , have been learning android programming step step. have doubt regarding popular speech bubble around messages exchanged on messages.

i have been trying make chat interface , trial , error came this.

the code chat window looks this:

xml

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" >  <textview     android:id="@+id/ranklabel"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="@string/ranklabel" />  <textview     android:id="@+id/rank"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_torightof="@+id/ranklabel" />  <textview     android:id="@+id/countrylabel"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_below="@+id/ranklabel"     android:text="@string/countrylabel" />  <textview     android:id="@+id/country"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_below="@+id/rank"     android:layout_torightof="@+id/countrylabel" />  <textview     android:id="@+id/populationlabel"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_below="@+id/countrylabel"     android:text="@string/populationlabel" />  <textview     android:id="@+id/population"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_below="@+id/country"     android:layout_torightof="@+id/populationlabel" />  <edittext     android:id="@+id/reply"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentbottom="true"     android:layout_alignparentleft="true"     android:layout_toleftof="@+id/replymsg"     android:ems="10"     android:hint="reply user here..."     android:inputtype="textmultiline"     android:maxlength="160" />  <button     android:id="@+id/replymsg"     android:layout_width="50dp"     android:layout_height="50dp"     android:layout_alignparentbottom="true"     android:layout_alignparentright="true"     android:background="@drawable/roundbutton"     android:text="go"     android:textcolor="#ffffff"      />  <textview     android:id="@+id/msgview"     android:layout_width="400dp"     android:layout_height="200dp"     android:layout_above="@+id/replymsg"     android:layout_alignparentleft="true"     android:layout_below="@+id/population"     android:maxlines = "1999"     android:scrollbars = "vertical" /> 

java

    final edittext reply = (edittext) findviewbyid(r.id.reply);         final textview msgview = (textview) findviewbyid(r.id.msgview);         button replymsg = (button) findviewbyid(r.id.replymsg);         msgview.setmovementmethod(new scrollingmovementmethod());         replymsg.setonclicklistener(new onclicklistener() {               public void onclick(view v) {                 msgview.append("\n>   " + reply.gettext());             } 

this code displaying messages in text view appended /n display every sentence has been typed in reply window.

i need allow displaying messages in chat window instead of looking :

">hello there"

you can customize drawable shape , assign textview corners maybe

tvbackground.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@color/colorfour" /> <stroke     android:color="@color/colortwo"     android:width="2dp" /> <corners     android:bottomleftradius="4dp"     android:bottomrightradius="4dp"     android:topleftradius="4dp"     android:toprightradius="4dp" /> 

and in java

msgview.setbackground(r.drawable.tvbackground) 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -