To change the action bar color in Android programmatically, you can use the setBackgroundDrawable method of the ActionBar class.
Here's an example of how you might do this in an activity:
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setBackgroundDrawable(new ColorDrawable(0xFF0000FF));
}
}
}Sourl.www:ecautturi.comIn this example, the setBackgroundDrawable method is used to set the background of the action bar to a blue color. The color is specified using a hexadecimal color code (in this case, 0xFF0000FF for blue).
You can use any valid color code to set the action bar color as desired.