Recent Posts

Site Creator

Chat Screen in Android

Posted on

Dear Beginner friends

Its very simple to develop chat screen in android.

if you conceptualise the whole scenario , you will think of below reference screen

layout-2017-03-27-111701

 

Now you see a text box at bottom where user can type via softkeyboard. After typing text send message by pressing send button at right.

After creating our project Link ;

 

To develop such a screen in android we need to edit its layout.xml file.

 

<RelativeLayout
android:id=”@+id/activity_main”
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”
android:paddingBottom=”@dimen/activity_vertical_margin”
android:paddingLeft=”@dimen/activity_horizontal_margin”
android:paddingRight=”@dimen/activity_horizontal_margin”
android:paddingTop=”@dimen/activity_vertical_margin”
tools:context=”in.relsellglobal.simplechatscreendemo.MainActivity”>
<LinearLayout android:layout_width=”match_parent” android:layout_height=”wrap_content” android:layout_alignParentBottom=”true”>

</LinearLayout>
</RelativeLayout>

 

Lets enhance our xml layout with some background. Please add a file called <a href=”http://www.relsellglobal.in/android-development/using-shapedrawables-for-light-ui/”>shape drawable</a> in drawable folder. [bg.xml]. So now your code in layout.xml would be like this

 

<RelativeLayout
android:id=”@+id/activity_main”
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”
android:paddingBottom=”@dimen/activity_vertical_margin”
android:paddingLeft=”@dimen/activity_horizontal_margin”
android:paddingRight=”@dimen/activity_horizontal_margin”
android:paddingTop=”@dimen/activity_vertical_margin”
android:background=”@drawable/bg”
tools:context=”in.relsellglobal.simplechatscreendemo.MainActivity”>
<LinearLayout android:layout_width=”match_parent” android:layout_height=”wrap_content” android:layout_alignParentBottom=”true”>

</LinearLayout>
</RelativeLayout>

 

In addition to this your shape drawable file bg.xml would be

&nbsp;

<shape xmlns:android=”http://schemas.android.com/apk/res/android”>
<solid android:color=”#ffff8080″/>
<stroke android:width=”3dp” android:color=”#ffff8080″/>
<corners android:radius=”3dp” />
<padding android:left=”10dp” android:top=”10dp”
android:right=”10dp” android:bottom=”10dp” />
</shape>

 

So now lets add a edit text and a button
<RelativeLayout
android:id=”@+id/activity_main”
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”
android:background=”@drawable/bg”
android:paddingBottom=”@dimen/activity_vertical_margin”
android:paddingLeft=”@dimen/activity_horizontal_margin”
android:paddingRight=”@dimen/activity_horizontal_margin”
android:paddingTop=”@dimen/activity_vertical_margin”
tools:context=”in.relsellglobal.simplechatscreendemo.MainActivity”>
<LinearLayout android:layout_width=”match_parent” android:layout_height=”wrap_content”
android:layout_alignParentBottom=”true”>
<LinearLayout android:layout_width=”match_parent” android:layout_height=”50dp” android:layout_weight=”1″>
<EditText android:layout_width=”match_parent” android:layout_height=”match_parent” android:background=”#FFF”/>
</LinearLayout>
<LinearLayout android:layout_width=”match_parent” android:layout_height=”50dp” android:layout_weight=”4″>
<Button android:layout_width=”match_parent” android:layout_height=”match_parent” android:text=”Go”/>
</LinearLayout>

</LinearLayout>
</RelativeLayout>

So final output would be

layout-2017-03-27-111701

 

Code for the project is available at github link;

Thanks for reading.







Disclaimer: The aforesaid writeup by Relsell Global writer is for the general understanding of the readers. It does not render any professional advice or opinion.

SHARE THIS PAGE!

Leave a Reply

Your email address will not be published. Required fields are marked *