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"

Need Your Help

Rails3 Whenever not working from cron, but perfectly from terminal

ruby-on-rails-3 cron centos5 whenever

Using Whenever 0.7.3, Rails 3.2.2, Ruby 1.9.3, Passenger 3.0.11 on a CentOS 5.6 server (I'm not using rvm). The problem is that the cron jobs created by whenever are clearly executed, I can see the...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.