登录屏幕UI更改

时间:2015-01-29 05:19:05

标签: android xml user-interface

我已经完成了主题为Theme.Holo.Light的登录界面,我得到了我的编辑字段,如下图所示,但想要将其更改为图像2.任何帮助将不胜感激。

更改为 - 在我当前的UI中,它只有浅蓝色下划线,我想将其更改为带有白色边框的盒子形状。 目前我正在烘烤错误消息,但我希望我的编辑字段边框改变,如图像2中所示 复选框边框是白色但不可见,想要使它成为白色的边框

图片1

enter image description here

IMAGE2

enter image description here

我的活动类代码

public class LoginActivity extends Activity {

    ProgressDialog prgDialog;
    EditText emailET;
    EditText pwdET;
    String email;
    String password;
    Button button;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_login);

        emailET = (EditText) findViewById(R.id.txt_user);
        pwdET = (EditText) findViewById(R.id.txt_pwd);
//      pwdET.setBackgroundResource(R.color.white);
        prgDialog = new ProgressDialog(this);
        prgDialog.setMessage("Please wait...");

        prgDialog.setCancelable(false);

        button = (Button) findViewById(R.id.btlogin);

        final Button button = (Button) findViewById(R.id.btlogin);
        button.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {

                try {

                    String email = emailET.getText().toString();
                    String password = pwdET.getText().toString();

                    if (Utility.isNotNull(email) && Utility.isNotNull(password)) {

                        if (Utility.validate(email)) {

                            if (emailET.getText().toString().equals(email)
                                    && pwdET.getText().toString()
                                    .equals(password)) {
                                CheckBox ch = (CheckBox) findViewById(R.id.ch_rememberme);
                                if (ch.isChecked())
                                    rememberMe(email, password); // save email

                            }

                            new LoginAsyncTask(LoginActivity.this).execute(
                                    email, password);

                            Toast.makeText(getApplicationContext(),
                                    "Asynctask started", Toast.LENGTH_SHORT)
                                    .show();

                        }
                        // When Email is invalid
                        else {
                            Toast.makeText(getApplicationContext(),
                                    "Please enter valid email",
                                    Toast.LENGTH_LONG).show();
                        }
                    }
                    // When any of the Edit View control left blank
                    else {
                        Toast.makeText(
                                getApplicationContext(),
                                "Please fill the form, don't leave any field blank",
                                Toast.LENGTH_LONG).show();
                    }
                } catch (Exception ex) {

                }

            }
        });

我的XML文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:orientation="vertical" >

    <Button
        android:id="@+id/btlogin"
        android:layout_width="225dp"
        android:layout_height="35dp"
        android:layout_below="@+id/ch_rememberme"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="16dp"
        android:background="#188e04"
        android:onClick="doLogin"
        android:text="LOGIN NOW"
        android:textColor="#ffffff"
        android:textSize="14sp" />

    <CheckBox
        android:id="@+id/ch_rememberme"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/btlogin"
        android:layout_below="@+id/txt_pwd"
        android:gravity="center"
        android:text="Remember login information"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="#ffffff" />

    <EditText
        android:id="@+id/txt_pwd"
        android:layout_width="265dp"
        android:layout_height="32dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:ems="10"
        android:gravity="center"
        android:hint="Enter Password"
        android:password="true"
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="#ffffff" />

    <EditText
        android:id="@+id/txt_user"
        android:layout_width="265dp"
        android:layout_height="32dp"
        android:layout_above="@+id/txt_pwd"
        android:layout_alignLeft="@+id/txt_pwd"
        android:layout_marginBottom="16dp"
        android:gravity="center"
        android:hint="Email Address"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="#ffffff" />

</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

您必须在xml中定义一些样式和形状,并使用此xml作为登录屏幕编辑文本背景。

您的登录屏幕 xml

&#13;
&#13;
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:orientation="vertical" >

    <Button
        android:id="@+id/btlogin"
        android:layout_width="225dp"
        android:layout_height="35dp"
        android:layout_below="@+id/ch_rememberme"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="16dp"
        android:background="#188e04"
        android:onClick="doLogin"
        android:text="LOGIN NOW"
        android:textColor="#ffffff"
        android:textSize="14sp" />

    <CheckBox
        android:id="@+id/ch_rememberme"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/btlogin"
        android:layout_below="@+id/txt_pwd"
        android:gravity="center"
        android:text="Remember login information"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="#ffffff" />

    <EditText
        android:id="@+id/txt_pwd"
        android:layout_width="265dp"
        android:layout_height="32dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:ems="10"
        android:gravity="center"
        android:hint="Enter Password"
        android:background="@drawable/loginstyle"
        android:password="true"
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="#ffffff" />

    <EditText
        android:id="@+id/txt_user"
        android:layout_width="265dp"
        android:layout_height="32dp"
        android:layout_above="@+id/txt_pwd"
        android:layout_alignLeft="@+id/txt_pwd"
        android:layout_marginBottom="16dp"
        android:background="@drawable/loginstyle"
        android:gravity="center"
        android:hint="Email Address"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="#ea2628" />

</RelativeLayout>
&#13;
&#13;
&#13;

Loginstyle.xml 将此文件放入可绘制文件夹

&#13;
&#13;
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
 
   <!--  view background color -->
    <solid
        
        android:color="#040404" >
    </solid>
 
    <!-- view border color and width -->
    <stroke
         android:width="1px"
         
        android:color="#ea2628" >
    </stroke>
 
   
    <!-- Here is the corner radius -->
    <corners
        android:bottomLeftRadius="3px"
        android:bottomRightRadius="3px"
        android:topLeftRadius="3px"
        android:topRightRadius="3px"   >
    </corners>
</shape> 
    
&#13;
&#13;
&#13;

在这里,我为两个文本视图都提供了单色,使用另一个文件用于不同的颜色,请参阅注释以更改颜色