Criando um formulário de login
Autor: Marcio de Souza | Publicado: 2012-04-19T16:56:00-07:00



Olá Pessoal,

Hoje vou apresentar o layout de um formulário de login, já estilizado, com Shape e Styles nos componentes utilizados.

Utilizando o modelo proposto neste projeto podemos criar layouts mais sofisticados para nossos programas.

Abaixo segue um print da estrutura do projeto.




Abaixo seguem todos os arquivos utilizados no projeto acima.


Arquivo shapebutton.xml
 &lt;?xml version="1.0" encoding="UTF-8"?&gt;
 &lt;shape 
    xmlns:android="http://schemas.android.com/apk/res/android"&gt;
    
    &lt;gradient 
        android:startColor="#96A5CE" 
        android:endColor="#1D3472"
        android:angle="270"/&gt; 

    &lt;stroke
        android:width="1dp"
        android:color="#1D3472" /&gt;
    
    &lt;corners
        android:radius="7dp" /&gt;
    
    &lt;padding
        android:left="15dp"
        android:top="5dp"
        android:right="15dp"
        android:bottom="5dp" /&gt;
    
 &lt;/shape&gt;


Arquivo shaplinear.xml
 &lt;?xml version="1.0" encoding="UTF-8"?&gt;
 &lt;shape 
    xmlns:android="http://schemas.android.com/apk/res/android"&gt;
            
    &lt;solid 
        android:color="#B9BFD1"/&gt; 
 
    &lt;padding
        android:bottom="2dp"
        android:left="2dp"
        android:right="2dp"
        android:top="2dp"/&gt;
          
    &lt;corners 
        android:bottomRightRadius="7dp" 
        android:bottomLeftRadius="7dp"     
        android:topLeftRadius="7dp" 
        android:topRightRadius="7dp"/&gt;
    
 &lt;/shape&gt;



Arquivo shaplinear.xml

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;shape 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"&gt;
    
    &lt;gradient 
        android:startColor="#96A5CE" 
        android:endColor="#1D3472"
        android:angle="270"/&gt; 
                 
    &lt;padding
        android:bottom="4dp"
        android:left="4dp"
        android:right="4dp"
        android:top="4dp" /&gt;
 
    &lt;corners 
        android:bottomRightRadius="1dp" 
        android:bottomLeftRadius="1dp"     
        android:topLeftRadius="7dp" 
        android:topRightRadius="7dp"/&gt;
    
&lt;/shape&gt;



Arquivo styles.xml
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;resources&gt;
   
    &lt;style name="TitleBarText"&gt;
        &lt;item name="android:id"&gt;@+id/title_text&lt;/item&gt;
        &lt;item name="android:layout_width"&gt;0dp&lt;/item&gt;
        &lt;item name="android:layout_height"&gt;fill_parent&lt;/item&gt;
        &lt;item name="android:layout_weight"&gt;1&lt;/item&gt;
        &lt;item name="android:gravity"&gt;center_vertical&lt;/item&gt;
        &lt;item name="android:textSize"&gt;20dp&lt;/item&gt;
        &lt;item name="android:paddingLeft"&gt;12dip&lt;/item&gt;
        &lt;item name="android:paddingRight"&gt;12dip&lt;/item&gt;
        &lt;item name="android:textStyle"&gt;bold&lt;/item&gt;
        &lt;item name="android:textColor"&gt;@android:color/white&lt;/item&gt;
        &lt;item name="android:singleLine"&gt;true&lt;/item&gt;
        &lt;item name="android:ellipsize"&gt;end&lt;/item&gt;
    &lt;/style&gt;

&lt;/resources&gt;



Arquivo main.xml
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:gravity="center_vertical"&gt;

    &lt;LinearLayout
        android:id="@+id/linearLayout1"
        android:background="@drawable/shapelinear"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:orientation="vertical" &gt;

        &lt;LinearLayout
            android:id="@+id/linearLayout2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:background="@drawable/shapetextview"
            android:orientation="horizontal" &gt;
            
            &lt;ImageView
             android:id="@+id/imageView1"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:src="@drawable/login48" /&gt;

         &lt;TextView
             style="@style/TitleBarText"
             android:id="@+id/tvLogin"
             android:layout_width="wrap_content"
             android:layout_height="fill_parent"
             android:gravity="right|center_vertical" 
             android:text="Login" /&gt;

        &lt;/LinearLayout&gt;
        
        &lt;LinearLayout
            android:id="@+id/linearLayout3"
            android:layout_marginTop="10dp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" &gt;

            &lt;TextView
                android:id="@+id/tvUsuario"
                android:textColor="#1D3472"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:gravity="right"
                android:layout_height="wrap_content"
                android:textStyle="bold"
                android:text="Usuário : " /&gt;

            &lt;EditText
                android:id="@+id/etUsuario"
                android:layout_width="0dp"
                android:layout_weight="2"
                android:layout_marginRight="10dp"
                android:layout_height="wrap_content"&gt;
                &lt;requestFocus /&gt;
            &lt;/EditText&gt;

        &lt;/LinearLayout&gt;
        
        &lt;LinearLayout
            android:id="@+id/linearLayout4"
            android:layout_marginTop="10dp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" &gt;

            &lt;TextView
                android:id="@+id/tvSenha"
                android:textColor="#1D3472"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:gravity="right"
                android:layout_height="wrap_content"
                android:textStyle="bold"
                android:text="Senha : " /&gt;

            &lt;EditText
                android:id="@+id/etSenhA"
                android:layout_width="0dp"
                android:layout_weight="2"
                android:layout_marginRight="10dp"
                android:inputType="textPassword"
                android:layout_height="wrap_content" &gt;
            &lt;/EditText&gt;

        &lt;/LinearLayout&gt;
        
        &lt;LinearLayout
            android:id="@+id/linearLayout5"
            android:layout_marginTop="10dp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:gravity="right"
            android:weightSum="3"&gt;

            &lt;CheckBox
                android:id="@+id/chkLembrar"
                android:layout_width="0dp"
                android:layout_weight="2"
                android:layout_marginRight="10dp"
                android:layout_height="wrap_content"
                android:text="Lembrar usuário" /&gt;
            
        &lt;/LinearLayout&gt;
                    
        &lt;RelativeLayout
            android:id="@+id/relativeLayout1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp" &gt;

            &lt;Button
                style="@style/TitleBarText" 
                android:id="@+id/btEntrar"
                android:layout_alignParentRight="true"
                android:layout_marginRight="10dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/checkBox1"
                android:background="@drawable/shapebutton"
                android:text="Entrar" /&gt;

        &lt;/RelativeLayout&gt;

    &lt;/LinearLayout&gt;

&lt;/RelativeLayout&gt;



Abaixo temos o resultado de nosso projeto.




Por enquanto é isso pessoal, espero que tenham gostado, assim que tiver novidades eu postarei com certeza.


Abaixo seguem outros links relacionados:
Pattern DashBoard -&nbsp;http://escoladeandroid.blogspot.com.br/2012/04/pattern-dashboard.html
Shape -&nbsp;http://escoladeandroid.blogspot.com.br/2012/04/android-shape.html



Desenvolvi o jogo&nbsp;Circus Puzzle Free&nbsp;ele é um quebra-cabeça e está publicado no Android Market, agradeço a todos que baixarem, jogarem e comentarem.





Desenv com qualidade!