View unanswered posts | View active topics It is currently 21 May 2013, 14:15



Reply to topic  [ 4 posts ] 
 Button Background 
Author Message
User avatar

Joined: 20 Jun 2011, 23:27
Posts: 12
Post Button Background
Καλησπέρα,

προσπαθώ να αλλάξω την εικόνα ενός button (έχει background μια εικόνα) μέσω κώδικα java αλλά δεν λειτουργεί.

Code:
public class DokimiActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     
       
        final Button button1 = (Button) findViewById(R.id.imagebutton1);
        button1.setOnClickListener( new OnClickListener() {
           public void onClick(View v) {
              //1ος τρόπος δεν λειτουργεί
              button1.setBackgroundResource(R.drawable.imagebuttononfocus);
              //2ος τρόπος ούτε αυτός λειτουργεί
              //button1.setBackgroundDrawable(getResources().getDrawable(R.drawable.imagebuttononfocus));
           }
        });
       
      }
       
       
}


Καμμία βοήθεια?

ευχαριστώ!

_________________
MSN : hellascasper@hotmail.com
Skype: hellascasper


16 Apr 2012, 16:36
Profile
User avatar

Joined: 12 Jul 2011, 18:34
Posts: 119
Post Re: Button Background
Εδω τι θες να κανεις?
Στο ονclick να αλλάζει το εικονίδιο?

_________________
x8
Αναλαμβάνω κατασκευή Android εφαρμογών...Πμ or Mail me
Θες και Εσυ να γινεις Android Developer? Android Youtube Tutorial


08 May 2012, 06:56
Profile
Site Admin
User avatar

Joined: 24 May 2008, 23:50
Posts: 626
Location: Athens
Post Re: Button Background
δεν σου κάνει η onClick, θα πρέπει να παίξεις με την onTouchEvent. http://developer.android.com/reference/ ... otionEvent)

ο σωστός τρόπος για να γίνει αυτό που θέλεις είναι με εναν selector.

_________________
Chief Software Engineer @ PinApps.com
Κωνσταντίνος Πολυχρόνης http://www.kospol.gr
Πρόσθεσε την εφαρμογή σου: http://greekandroidapps.gr/


16 May 2012, 19:17
Profile WWW

Joined: 29 Jun 2012, 02:45
Posts: 20
Post Re: Button Background
Σωστό με την onClick θα ήταν αν έπαιζες με κάποιο imageview και στο onClick του κουμπιού σου άλλαζες την εικόνα εκείνη!


29 Jun 2012, 02:48
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware.