0

I am making an android app.. In My xml file I have tried the below code:--

activity_registration

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/blue">
 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
    <TextView
    android:id="@+id/txt22"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Dubai Tour and Travels"
    android:textColor="@color/white"
    android:layout_marginTop="10dp" 
    android:textStyle="bold"
    android:typeface="monospace"
    android:layout_gravity="center"/>
</LinearLayout>
<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
     android:layout_marginTop="40dp" >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" 
         android:layout_margin="10sp" 
         android:background="@color/shadow"
         android:paddingLeft="15dip"
         android:paddingRight="15dip">
<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Name"
    android:textColor="@color/black"
    android:layout_marginTop="10dp" 
    android:textStyle="bold"
    android:typeface="monospace"/>
        <EditText
    android:id="@+id/fieldFirstOpinion"
    android:layout_width="250dp"
    android:layout_height="50dp" 
    android:layout_gravity="center"
    android:minHeight="10sp"
    android:hint="Name"/>
     <TextView
    android:id="@+id/tx2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Email Id"
    android:textColor="@color/black"
    android:layout_marginTop="10dp" 
    android:textStyle="bold"
    android:typeface="monospace"/>
        <EditText
    android:id="@+id/ed2"
     android:layout_width="250dp"
     android:layout_height="50dp" 
      android:layout_gravity="center"
    android:minHeight="10sp"
    android:hint="Email id"/>  
   <TextView
    android:id="@+id/tx3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Mobile Number"
    android:textColor="@color/black"
    android:layout_marginTop="10dp" 
    android:textStyle="bold"
    android:typeface="monospace"/>
       <EditText
    android:id="@+id/ed3"
     android:layout_width="250dp"
     android:layout_height="50dp" 
    android:layout_gravity="center"
    android:minHeight="10sp"
    android:hint="Mobile Number"
    android:inputType="number"/>
<TextView
    android:id="@+id/tx4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Mobile Number"
    android:textColor="@color/black"
    android:layout_marginTop="10dp" 
    android:textStyle="bold"
    android:typeface="monospace"/>
         <Spinner
             android:id="@+id/spinner1"
             android:layout_width="250dp"
             android:layout_height="50dp" 
             android:layout_gravity="center"/>
          <TextView
    android:id="@+id/tx5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Address"
    android:textColor="@color/black"
    android:layout_marginTop="10dp" 
    android:textStyle="bold"
    android:typeface="monospace"/> 
          <EditText
    android:id="@+id/ed4"
     android:layout_width="250dp"
    android:layout_height="50dp" 
    android:layout_gravity="center"
    android:minHeight="10sp"
    android:hint="Address" />
    <Button
    android:id="@+id/button1"
   android:layout_width="100dp"
   android:layout_height="50dp" 
   android:layout_gravity="center"
    android:text="Submit" />    
    </LinearLayout>
</ScrollView>

In this code I am getting my all data. But I want the font and the style view as like:--That example page In this page the textviews,edittext,button,spinner are arranged in a good way.they are very small size.. How can I achieve that??

user_apr
  • 719
  • 2
  • 10
  • 27

2 Answers2

1

It seems in your screenshot they used @android:drawable/editbox_background as EditText's background. You have to create a rounded corner button in xml and placed that in drawable folder. Solution 1 :

  • create a folder named drawable inside res folder in your project.
  • create a xml file inside that drawable folder named rounded_corner_btn

rounded_corner_btn xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <solid android:color="@color/yellow" />

    <corners
        android:bottomLeftRadius="24dp"
        android:bottomRightRadius="24dp"
        android:topLeftRadius="24dp"
        android:topRightRadius="24dp" />

</shape>

activity_registration xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/blue" >

        <TextView
            android:id="@+id/txt22"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="10dp"
            android:text="Dubai Tour and Travels"
            android:textColor="@color/white"
            android:textStyle="bold"
            android:typeface="monospace" />

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_marginTop="40dp" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10sp"
            android:background="@color/wallet_highlighted_text_holo_dark"
            android:orientation="vertical"
            android:paddingLeft="15dip"
            android:paddingRight="15dip" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:text="Name"
                android:textColor="@color/black"
                android:textStyle="bold"
                android:typeface="monospace" />

            <EditText
                android:id="@+id/fieldFirstOpinion"
                android:layout_width="250dp"
                android:layout_height="50dp"
                android:layout_gravity="center"
                android:hint="Name"
                android:minHeight="10sp"
                android:background="@android:drawable/editbox_background" />

            <TextView
                android:id="@+id/tx2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:text="Email Id"
                android:textColor="@color/black"
                android:textStyle="bold"
                android:typeface="monospace" />

            <EditText
                android:id="@+id/ed2"
                android:layout_width="250dp"
                android:layout_height="50dp"
                android:layout_gravity="center"
                android:hint="Email id"
                android:minHeight="10sp"
                android:background="@android:drawable/editbox_background" />

            <TextView
                android:id="@+id/tx3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:text="Mobile Number"
                android:textColor="@color/black"
                android:textStyle="bold"
                android:typeface="monospace" />

            <EditText
                android:id="@+id/ed3"
                android:layout_width="250dp"
                android:layout_height="50dp"
                android:layout_gravity="center"
                android:hint="Mobile Number"
                android:inputType="number"
                android:minHeight="10sp"
                android:background="@android:drawable/editbox_background" />

            <TextView
                android:id="@+id/tx4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:text="Mobile Number"
                android:textColor="@color/black"
                android:textStyle="bold"
                android:typeface="monospace" />

            <Spinner
                android:id="@+id/spinner1"
                android:layout_width="250dp"
                android:layout_height="50dp"
                android:layout_gravity="center"
                android:background="@android:drawable/btn_dropdown" />

            <TextView
                android:id="@+id/tx5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:text="Address"
                android:textColor="@color/black"
                android:textStyle="bold"
                android:typeface="monospace" />

            <EditText
                android:id="@+id/ed4"
                android:layout_width="250dp"
                android:layout_height="50dp"
                android:layout_gravity="center"
                android:hint="Address"
                android:minHeight="10sp"
                android:background="@android:drawable/editbox_background" />

            <Button
                android:id="@+id/button1"
                android:layout_width="120dp"
                android:layout_height="50dp"
                android:layout_gravity="center"
                android:text="Submit"
                android:textColor="@color/black_overlay"
                android:background="@drawable/rounded_corner_btn" />
        </LinearLayout>
    </ScrollView>
</RelativeLayout>

Solution 2: Create .png images and set those images as background of those EditTexts, Spinner and Button using android:background="@drawable/image_name"


For custom font place a font inside asset folder. In code do like this

// Font path
String fontPath = "fonts/Face Your Fears.ttf"; //Face Your Fears.ttf is font name with extension 
// text view label
TextView urTxtView = (TextView) findViewById(R.id.urTxtView); 
// Loading Font Face
Typeface tf = Typeface.createFromAsset(getAssets(), fontPath); 
// Applying font
urTxtView.setTypeface(tf);

You can take a look at this tutorial for setting up custom font

enter image description here

Kaushik
  • 6,150
  • 5
  • 39
  • 54
  • Thnx..Its working..But suppose in my project I have a lot of textviews/edittexts mand many more...Then how everty time I have to do "urTxtView.setTypeface(tf);" that type???????????????????is there any other solution? If I want to allow the font to whole app..what I have to do? – user_apr Oct 30 '14 at 06:02
  • yes u have to do `urTxtView.setTypeface(tf);` for every *TextView* – Kaushik Oct 30 '14 at 06:06
  • Ok..thank you..Do you know how to add "font.ttf"(in asset folder) in style.xml as a theme which uses that fonts – user_apr Oct 30 '14 at 06:12
0

First of all try to not set the static height and width. Use wrap_content or match_parent with some margins(Android has a lot of screen sizes and on some devices your view can look very strange).

Create 9.patch file for background (http://developer.android.com/tools/help/draw9patch.html) in your Views. Use selectors for button.

Use shape for your EditTexts etc.(https://stackoverflow.com/a/3264140/3864698)

Customize your Spinner (http://mrbool.com/how-to-customize-spinner-in-android/28286)

Community
  • 1
  • 1
QArea
  • 4,955
  • 1
  • 12
  • 22