I have set up an Activity with one EditText and one Button and I'm trying do the following thing: the user types a color in hexadecimal in the EditText, presses the Button and then the NavBar/ActionBar changes its color to the typed value.
The only way for changing those within the app that I found was to change the Style of the NavBar/ActionBar to a premade one, but I'd like to be able to set it to a custom color.
public class VisualTweaks extends Activity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_visual_tweaks);
Button colorButton = (Button) findViewById(R.id.countButton);
EditText colorEditText = (EditText) findViewById(R.id.colorEditText);
colorButton.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (android.os.Build.VERSION.SDK_INT >= 21)
getWindow().setNavigationBarColor(getResources().getColor(R.color.navigationbar_color));
}
}
This is a quick fix that i found for the actionBar :
getActionBar().setBackgroundDrawable(new ColorDrawable(0xff00DDED));
getActionBar().setDisplayShowTitleEnabled(false);
getActionBar().setDisplayShowTitleEnabled(true);
ActionBar actionBar;
actionBar = getActionBar();
ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#93E9FA"));
actionBar.setBackgroundDrawable(colorDrawable);
as u same colorDrawable use for your navigation bar also
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.