indi mars
indi mars

Reputation: 133

how to change the background color of android phone screen

I am new in learning Android and so far I have been focused on functionality, but now I am starting to work with layouts.

Issue:-- My app has a button and on its click, I send a sms to registered number.But as soon as the button is clicked I want change the user's phone screen background color to red and same with the front notification led.(As soon as the user pushes the button, the app finishes....so my idea is , user should know that button was pushed and message is sent. so the background of scrren should be in alert position.)

Is there a way to do this? I was searching net and found that notification led behaves different for different manufacturers.Is there any generic way to do this, so that the apps behave same in all android phone brands?? Any code snippet or any hits will be highly appreciated.

Upvotes: 0

Views: 8829

Answers (2)

Mauker
Mauker

Reputation: 11497

The notification LEDs are not a standard feature on Android. That said, you can't have a single method which will handle the blinking for all Android devices.

An way to solve this issue is to create a generic method, which will check the brand of the phone, and use the appropriated method to blink the LED. Something like:

private void blinkLED() {
    String man = android.os.Build.MANUFACTURER; 

    if (man.equals("SAMSUNG")) {
        // Do Samsung LED blinking here.
    }
    else if (man.equals("HTC")) {
        // Do HTC LED blinking here.
    }
    else {
        // ...
    }
}

And to change your background color, get the reference for your root layout, and call the setBackgroundColor method, which all objects who inherits from android View have.

RelativeLayout lv = (RelativeLayout) findViewById(R.id.relativelayout);
Button bt = (Button) findViewById(R.id.button);

bt.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View view) {
        lv.setBackgroundColor(Color.rgb(204,0,0));
    }
});

Edit: From what I could understand, you want to notify the user that your message was sent. I can suggest an easy way for you to do it. Use the ProgressDialog and AlertDialog classes. Use it if you want to show the progress of the sending process to the user and notify when the process is done. To start a progress dialog is simple, just add this line:

// this refers to a Context, the second argument is the title of the dialog, the third argument is the body message of the dialog, the fourth argument is whether your dialog is indeterminate or not, the last argument tells if your dialog can be canceled or not.
ProgressDialog pd = ProgressDialog.show(this,"Title of dialog","(Body message) Sending message",true,false); 

And to cancel it, or disable it, just call:

pd.dismiss();

And to show an AlertDialog, just do the following.

new AlertDialog.Builder(getApplicationContext())
                                .setTitle("Title")
                                .setMessage("Your message was sent!")
                                .setPositiveButton("OK",null)
                                .show();

That should do what you want.

Upvotes: 0

Miriana Itani
Miriana Itani

Reputation: 915

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:id="@+id/layout"
    android:layout_height="match_parent"
   >
<TextView
        android:id="@+id/save"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="@drawable/button"
        android:layout_alignParentBottom="true"
        android:layout_marginRight="10dp"
        android:layout_marginBottom="10dp"
        android:text="Save"
        android:gravity="center"
        android:textSize="18sp"
        android:textColor="#ffffff"
        android:layout_marginLeft="10dp"/>
</LinearLayout>

In the activity:

LinearLayout layout= (LinearLayout) findViewById(R.id.layout);
TextView save=(TextView) findViewById(R.id.save);

 save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                layout.setBackgroundColor(Color.rgb(255,32,32));
            }
        });

Upvotes: 1

Related Questions