Search code examples
androidpsd

How to put a custom .psd button in android layout?


I have a .psd file and I want to use it as a button in my app. I also have the pressed version of that button. How can I put it in the layout and make it to show the pressed state when the button is clicked?


Solution

  • As far as my knowledge goes android does not support .psd. Convert it to a jpg or png and you will be golden.

    Here is a list and more information on what formats android supports https://developer.android.com/guide/appendix/media-formats.html

    And here is a quick way to change the button:

    You need two images (image1 and image2) in the drawable folder and then change between them like this

    Button b1;
    ImageView iw;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
       b1 = (Button) findViewById(R.id.button1);
       b1.setOnClickListener(this); 
    
       iw = (ImageView) findViewById(R.id.image1);
    }
    
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        if (v == b1)
        {
            iw.setImageResource(R.drawable.image2);
        }
    
    }
    

    }

    Hope this helps a bit