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>
Related
Seems pretty simple question, but could't find any answer.
How to change the toolbar title.
The toolbar is created by AppCompat Activity,not a custom created one.
It has the app name as default.I would like to change its Name corresponding to the action the activity performs.
Note : I can change custom toolbar title using the below code,so please i am not looking for that.
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setTitle("My Title");
You can set default Toolbar title as following:
YourActivity.this.setTitle("Your Title");
For fragment:
getActivity().setTitle("Your Title");
getSupportActionBar().setTitle("Title")
Set ActionBar title based on your need
ActionBar ab = getActionBar();
ab.setTitle("My Title");
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.
I am setting up my Toolbar in my main activity and trying to change the background color with different fragments.
So basically, I am trying to access the Toolbar object inside fragment and set different background color.
Few things which I have tried to do is :
Access toolbar like:
((ActionBarActivity)getActivity()).getSupportActionBar().setBackgroundColor(XXX);
But I am unable to access the setBackgroundColor function inside fragment. It is perfectly working inside the Main Activity.
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable("COLOR"));
or
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0000ff")));
Have a look This or This
It is very easy to change the ToolBar, Actionbar color.
ActionBar bar = getSupportActionBar();
bar.setBackgroundDrawable(new ColorDrawable("COLOR"));
or
ActionBar bar = getSupportActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0000ff")));
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);