0

Hi i'm trying to recreate this button style more specifically the 'view basket' button. waitrose app The button needs to have multiple lines of text each with a different text size and font colour etc.

Here's the code so far. I've created the button and its displays correctly but when you click on it the state pressed isn't working. Where am I going wrong. Thanks in advance.

xml button file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" 

    android:state_pressed="true"
    android:state_focused="true"
    android:background="@drawable/button_bg" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Some Text"

    android:state_pressed="false"
    android:state_focused="false"
        android:textColor="#ffffff" />

     <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Some Text"

    android:state_pressed="false"
    android:state_focused="false"
        android:textColor="#ffffff" />

</LinearLayout>

java file code:


    package com.buttons2;

    import com.buttons2.R;

    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.Button;

    public class Buttons2Activity extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            Button button = (Button) findViewById(R.id.button1);
            setContentView(R.layout.button);


        }
    }

1 Answer 1

0

I think you will probably need to write some code to handle clicks on the text & image, and use that to specifically set the selected/unselected status of the main, container View (to it shows the correct pressed button status).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.