Codes for modifying Action Bar in Sketchware - BD HELP ZONE
We can modify the Action Bar or Title bar in our Sketchware project, by using simple codes in onCreate method. Below I provide a few of those codes.
Change title of Action Bar
ActionBar ab = getActionBar();
ab.setTitle("Title");
Replace the underlined text with the title you want to set.
Change subtitle of Action Bar
ActionBar ab = getActionBar();
ab.setSubtitle("subtitle");
Replace the underlined text with the subtitle you want to set.
Show App icon in Action Bar
ActionBar ab = getActionBar();
ab.setDisplayShowHomeEnabled(true);
Set an image as icon in Action Bar
Add the image to be displayed in Action Bar using Image Manager in your sketchware android project. Then add the following code in onCreate event.
ActionBar ab = getActionBar();
ab.setIcon(getDrawable(R.drawable.imagename));
ab.setDisplayShowHomeEnabled(true);
Replace the underlined text with name of the image added using Image Manager.
Use Custom view in Action Bar
ActionBar ab = getActionBar();
ab.setCustomView(R.layout.custom);
ab.setDisplayShowCustomEnabled(true);
Replace the underlined text with name of your Custom xml file (the new CustomView you added). The CustomView can be used to add titles and subtitles of different colors by using this method. It can be used to add more than two Textviews, or more image icons.
Hide Action Bar
ActionBar ab = getActionBar();
ab.hide();
Hide Action Bar Title
ActionBar ab = getActionBar();
ab.setDisplayShowTitleEnabled(false);
Use an image as Action Bar background
ActionBar ab = getActionBar();
ab.setBackgroundDrawable(getDrawable(R.drawable.imagename));
Replace the underlined text with name of the image, which is to be used as background of Action Bar.
Change Action Bar background color
ActionBar ab = getActionBar();
ab.setBackgroundDrawable(new android.graphics.drawable.ColorDrawable(Color.parseColor("#AA666D")));
Replace the underlined text with the desired hex color code.
* To modify the ActionBar in a project using AppCompat and design, instead of using ActionBar ab = getActionBar();
use following code:
android.support.v7.app.ActionBar ab = getSupportActionBar();
* The best way to change color of ActionBar is to do it in the settings of the project. Change colorPrimary.
The videos below show how to use these codes.
Comments
Post a Comment