I am having an Activity that extends the AppCompatActivity. I am using the theme Theme.AppCompat.Light.DarkActionBar. Now, the text color of the TitleText in the ActionBar shows up black. I want to set this color to white.
How can this be possibly achieved ?
Do I change the theme to something else (if yes then what) or can I change the color by making changes through the ThemeEditor available in the latest version of the Android Studio or can something be done with the getSupportActionBar() programmatically ?
I personally chose the programmatical way.
In your code, you can assign a custom layout to your ActionBar.
Like this:
android.support.v7.app.ActionBar mActionBar = getSupportActionBar();
mActionBar.setDisplayShowTitleEnabled(false);
mActionBar.setDisplayUseLogoEnabled(false);
mActionBar.setDisplayHomeAsUpEnabled(false);
mActionBar.setDisplayShowCustomEnabled(true);
mActionBar.setDisplayShowHomeEnabled(false);
ViewGroup actionBarLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.topbarclassic,null);
mActionBar.setCustomView(actionBarLayout);
Then just change the text color of your textview containing the text inside the ActionBar as following:
android:textColor="#FFFFFF"
Try to do this way in your Activity
getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#DCDCDC")));
You can simply change the action bar tittle color using this code
You add below code to your Oncreate method
setTitleColor(YOUR COLOR);
Hope this helps.
Related
I don’t know what the real name of this is, but I want to change the top menu for an image or button. Someone can tell me what the name is and how do that in my android aplication?.
something like it!!!
in your menu xml add this in the item tag android:icon="#drawable/youricon"
app:showAsAction="always"
If you mean the custom text, you can add custom vews in your toolbar. The toolbar is just a viewgroup where you can add views inside. See this as an example.
If you mean to add a custom image instead of the back arrow, you can switch it with the toolbar.setNavigationIcon(Drawable drawable) method.
If you want to display the default arrow, then try with this (after setting the toolbar).
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
There's a way to know the color of hold event on action bar? Like image below:
The theme is Theme.AppCompat.Light
I just want the color value... but, how?
you can achieve it by using custom action bar.
Add in onCreate methode:
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
// create xml in layout and inflate into view.
View v = getLayoutInflator().inflate(R.layout.search, null);
// here you can find id add listener on add button.
Button addBtn = (Button)v.findViewById(R.id.addBtn);
addBtn.setonClickListener(this);
//Now add view in your action bar.
actionBar.setCustomView(v);
I think it will help.
This color is defined in xml file. you can create your own style by using:
actionbar style generator
or you can see the source code of
Theme.AppCompat
in summary this value is set statically and you can find it without needing to get it at the runtime because it is what you have styled.
for other part of your app you can create theme with
android holo colors
if you want the color value here it is:
The color is
Can I design my Android ActionBar like this?
If yes, give me a starter. I am not new to android design.
Application name with logo is already centered but the little red strip on bottom is difficult as fas as I can understand. If somebody can help.
create custom layout and design whatever you want then add that layout into the actionbar object.
ActionBar actionBar = getSupportActionBar(); //to support lower version too
actionBar.setDisplayShowCustomEnabled(true);
View customView=getLayoutInflater().inflate(R.layout.yourlayout, null);
actionBar.setCustomView(customView);
Create a custom layout according to your requirement in an xml file say,
activity_custom_actionbar.xml
Then include this in your java file using,
ActionBar actionBar = getActionBar();
actionBar.setCustomView(R.layout.activity_custom_actionbar);
getActionBar().setDisplayShowCustomEnabled(true);
In my application a have an ActionBar with Tabs as navigation mode. I also use a custom View which adds another "line" to the ActionBar. Setup looks like:
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(R.layout.ab);
Typeface font = Typeface.createFromAsset(getAssets(), "cs_regular.ttf");
TextView title = (TextView) actionBar.getCustomView().findViewById(R.id.tvActionTitle);
title.setTypeface(font);
The problem: I do not want an icon to be shown, but when I use actionBar.setDisplayShowHomeEnabled(false); my custom layout gets placed BELOW the Tabs and I need it to be above the Tabs in the ActionBar. Setting it to true places the layout as I need it, but shows the unnecessary icon.. any suggestions?
I assume by icon you mean the app icon. You can essentially make it invisible using styles. Add this to the style your Activity is using:
<item name="android:icon">#android:color/transparent</item>
I am using
getSherlockActivity().getSupportActionBar().setBackgroundDrawable(new ColorDrawable(0xff00ACED));
To change the color of my action bar in a fragment and it works. But if i open this fragment then open another fragment that calls this method with a different color the actionbar doesn't change to the desired color. Instead it turns to a white color instead of the color I set it to.
this is a quick fix that i found
mActionBar.setBackgroundDrawable(new ColorDrawable(0xff00DDED));
mActionBar.setDisplayShowTitleEnabled(false);
mActionBar.setDisplayShowTitleEnabled(true);
Try this,
Method1:
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(0xff00FFED));
Method2:
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources()
.getColor(R.color.bg_color)));
Method3:
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#3A1212")));
Kotlin
supportActionBar?.setBackgroundDrawable(ColorDrawable(ContextCompat.getColor(this, android.R.color.black)))
I had the same problem, answer from user1634451 worked but only once (would not enable several color switches in a row)
This definitely fixed it:
bar.setBackgroundDrawable(new ColorDrawable(getResources()
.getColor(R.color.app_bar_online)));
Instead of directly linking to the color doing new ColorDrawable(R.color.app_bar_online)
getColor is deprecated. use ContextCompat :
bar.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(context, R.color.app_bar_online)));
If you want to set the color of the ActionBar and have the color as a String, this seems to work for me.
getSupportActionBar().setBackgroundDrawable(
new ColorDrawable(Color.parseColor("#993b3c4e")));
You may have to enable & disable the title to get it to refresh/display properly like in the answer given by user1634451, but I didn't need to in my case.
If you want to avoid deprecation you can used
val mActionBar: ActionBar? = supportActionBar
mActionBar.setBackgroundDrawable(ColorDrawable(ContextCompat.getColor(this, R.color.red)))
Kotlin Language
If you want want to change actionbar color or background pragmatically then simply use,
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getSupportActionBar().setBackgroundDrawable(getDrawable(R.drawable.white_background));
}
white_background.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#fff" />
((AppCompatActivity) getActivity()).getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary)));
In the fragment and Java