Button in dialog not behaving as a button when clicked

After create and testing my custom dialog I've noticed that my button does not show any visual sign of change (such as the ripple effect or highlighting) when clicked. Does anyone know what I'm doing wrong and how to resolve this issue?

XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin">

    <Button
        android:id="@+id/world"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="10dp"
        android:padding="10dp"
        android:background="@color/green"
        android:textColor="@color/white"
        android:text="@string/world"
        android:textAllCaps="false"
        style="@android:style/TextAppearance.Medium"/>
</LinearLayout>

Java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.action_other_lines) {
        final Dialog dialog = new Dialog(this);
        dialog.setContentView(R.layout.dialog_hello_world);
        dialog.setTitle("Dialog");

        Button world = (Button) dialog.findViewById(R.id.world);
        world.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        dialog.show();
    }

    return super.onOptionsItemSelected(item);
}

Answers


You override the default onClick effect by putting a background color.

android:background="@color/green"

You can do it by creating a custom background xml file on drawable, like this.

custom_background.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/Pressed_Color" />
<item android:state_activated="false"  android:drawable="@color/green"/>
</selector>

then you call it on the button styling as like this:

android:background="@drawable/custom_background"

when you change your default appearance, you should handle different state if you want like this

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/button_sel" android:state_selected="true" />
    <item android:drawable="@drawable/button_sel" android:state_pressed="true" />
    <item android:drawable="@drawable/button_unsel" />
</selector>

save this as xml drawable and add as android:background


Need Your Help

1 million sentences to save in DB - removing non-relevant English words

database hadoop nlp classification sentiment-analysis

I am trying to train a Naive Bayes classifier with positive/negative words extracting from a sentiment. example:

AsyncTask without callback interface

java android callback android-asynctask

I'm trying to resolve this problem: I have a class that extends from AsyncTask, that execute some http methods, something like this: