2013-05-15 46 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

如何修改按鈕的大小? –