2013-05-15 66 views
0

我尝试制作用于登录的图像按钮。但结果很奇怪。请参阅附件。 enter image description here奇怪的图像按钮结果

奇怪的是图像的按钮在按钮里面...

希望对您有所帮助。

这是XML代码...

<ImageButton 
     android:id="@+id/loginButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/chkRememberMe" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="30dp" 
     android:src="@drawable/login_off" /> 

这是为登录按钮的Java代码...

imageButtonLogin = (ImageButton) findViewById(R.id.loginButton); 

imageButtonLogin.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       String inputPassword = passwordEditText.getText().toString(); 
       if (password.isEmpty()) { 
        showDialog(DIALOG_ALERT); 
       } else { 

        String inputUserName = userNameEditText.getText() 
          .toString(); 
        Contact contact = new Contact(); 
        contact.setUsername(inputUserName); 
        contact.setPassword(inputPassword); 
        if (contactDb.searchContact(contact)) { 
         // logged in 
         /*Toast.makeText(getApplicationContext(), 
           getResources().getString(R.string.loggedIn), 
           Toast.LENGTH_LONG).show();*/ 
         Intent newActivity = new Intent(); 
         //go to AudioRecoder page 
         newActivity 
           .setClass(MainActivity.this, AudioActivity.class); 
         startActivity(newActivity); 

        } else { 
         // login failed 
         showDialog(DIALOG_ALERT); 
        } 
       } 
      } 
+0

什么附件 – Blackbelt

+0

请解释一下,*完全准确地*,什么是“怪异”。另外,请在您设置按钮的地方提供XML或Java。 – CommonsWare

+1

试着设置你的'ImageButton'而不是'src'的背景。 – GrIsHu

回答

1

您需要使用

android:background="@drawable/login_off" 

代替的src像你一样。

+0

谢谢!有用。但是我怎样才能修改按钮的大小?寻求帮助! –

+0

或者只是为了放置背景透明:android:background =“@ android:color/transparent”' – Houcine

+0

@AnthonyLo你需要让你的图像本身变大。或者甚至更好地制作9patch,以适应您使用的任何尺寸。 – FoamyGuy

0
<ImageButton 
     android:id="@+id/loginButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/chkRememberMe" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="30dp" 
     android:background="@null" 
     android:src="@drawable/login_off" /> 

你可以设置背景或trasparent android:background="#00FFFFFF"或为空android:background="@null"

+0

如何修改按钮的大小? –