1

我想创建一个登录表单。但我是 android 的新手,所以我不能正确地做到这一点。我必须把公司的标志放在它的标题上。之后,标题将像登录到您的帐户,然后在用户名和密码框中。所以我发布我的 xml 请更新它。谢谢...

这就是我必须从这个链接创建它的方法,请检查这个 http://s23.postimg.org/btie12dvv/Login_Page2.jpg

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#5F04B4"
    android:orientation="vertical" >


    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="User Name"
            android:textColor="#ffffff"
            android:textSize="13dp"
            android:textStyle="bold" />

        <EditText
            android:id="@+id/edtUserName"
            android:layout_width="200dp"
            android:layout_height="wrap_content" >
        </EditText>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Password"
            android:textColor="#ffffff"
            android:textSize="13dp"
            android:textStyle="bold" />

        <EditText
            android:id="@+id/edtPassword"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:password="true" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/btnLogin"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:text="Login" />
    </LinearLayout>

</LinearLayout>
4

3 回答 3

5

在标题中设置公司徽标:

getActionBar().setHomeButtonEnabled(true);
Drawable d=getResources().getDrawable(R.drawable.company_logo.png);
getActionBar().setBackgroundDrawable(d);

设置标题:登录

getActionBar().setTitle("Login");

我希望它会帮助你。

于 2013-07-10T05:55:11.133 回答
1

我创建了一个示例代码。您需要用示例之一替换正确的图像。

布局代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView
    android:id="@+id/imgLogo"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:src="@drawable/ic_launcher" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:layout_below="@+id/imgLogo"
    android:background="#092EA1"
    android:orientation="vertical"
    android:paddingBottom="10dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10dp"
        android:gravity="center_horizontal"
        android:text="Login to Your Account"
        android:textColor="@android:color/white"
        android:textSize="25sp" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="260dp"
            android:layout_height="40dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="17dp"
            android:layout_marginTop="15dp"
            android:background="@android:color/darker_gray" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/imageView1"
            android:layout_alignLeft="@+id/imageView1"
            android:layout_alignRight="@+id/imageView1"
            android:layout_alignTop="@+id/imageView1"
            android:layout_marginLeft="40dp"
            android:hint="Usrname" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="260dp"
            android:layout_height="40dp"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/imageView1"
            android:layout_marginLeft="17dp"
            android:layout_marginTop="15dp"
            android:background="@android:color/darker_gray" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/imageView2"
            android:layout_alignLeft="@+id/imageView2"
            android:layout_alignRight="@+id/imageView2"
            android:layout_alignTop="@+id/imageView2"
            android:layout_marginLeft="40dp"
            android:hint="Password"
            android:inputType="textWebPassword" />

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/imageView2"
            android:layout_below="@+id/imageView2"
            android:layout_marginTop="26dp"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/imageView3"
            android:layout_alignRight="@+id/imageView2"
            android:text="Forget Password?"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </RelativeLayout>
</LinearLayout>
</RelativeLayout>

这看起来像,

在此处输入图像描述

于 2013-07-10T06:39:05.137 回答
0
after 1st LinearLayout (root) you can write these lines:

<RelativeLayout
        android:id="@+id/headerLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="top" >

        <View
            android:id="@+id/headerView"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_alignParentTop="true"
            android:background="@drawable/Your-header-file-name" />
</RelativeLayout

或者,您可以使用 LinearLayout 而不是 Relative。我使用这个是因为它不会影响您的 LinearLayout。对于初学者来说,为 LinearLayout 使用权重是一个很好的做法,例如:

<LinearLayout (root)
android:orientation="vertical"
android:weightSum ="2" >

    <LineaLayout (child1)
        android:layout_weight="1"/>
    <LineaLayout (child2)
        android:layout_weight="1"/>

</LinearLayout>

这会将您的布局划分为权重 1。因此您将获得孩子 1 的一半屏幕和孩子 2 的剩余一半

于 2013-07-10T05:57:36.897 回答