How To Change Included Toolbar Title And Drawable? - android

I have a hard time finding on how to change the Toolbar title and it's drawable in every and each Activity.
There is something on Android Documentation that states that to minimize APK size. It is recommended to re-used components.
I create a separate layout, and <include layout=""/> to each of my Activities like Help, About , and etc. I also put android:label="Title" on Manifest File.
Toolbar.xml
My Main:
How do I access this included Toolbar DRAWABLE and TITLE in my Activities ?
Update: I removed ActionBar .

You are using Toolbar. So no need to do anything with ActionBar. Just set your Toolbar as supportActionBar. Then set title and icon to your Toolbar.
Use the below code:
mToolbar = (Toolbar)findViewById(R.id.Toolbar);
setSupportActionBar(mToolbar);
setTitle("About");
getSupportActionBar.setIcon(R.id.ic_arrow_back_black_24dp);
And, Remove all your mActionBar codes. Hope this helps.

well you set the support action to your custom toolbar,yet you ignore it and use mActionBar, see where i am going with this? setIcon , and setTitle should all be called relative to your custom toolbar.

Related

Change the App name to some other text in the top bar

Can please someone tell me how to change the App name in the top bar of my android App that gets displayed by default to some other text? I have seen this in a few Apps I used before. I'm building my first Android App and don't have that much experience with this stuff... thank you :)
after
setContentView(R.layout.layout_name);
simply add
setTitle("title_name");
this will change the name of your current activity in top bar or toolbar and i think your activity should extend AppCompactActivity
it is easier if you convert the actionbar (which I think is the bar you mean) into a toolbar if you want to do further modifications to it (as I assume):
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
to change the title then simply call actionbar.setTitle as shown here:
actionBar = getSupportActionBar();
actionBar.setTitle("Your Title");
and if you want a subtitle add:
actionBar.setSubtitle("Your Subtitle");
If you are using the new support library, you should use this:
Toolbar toolber = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(Toolbar);
getSupportActionBar().setTitle("App Title");

To create Swipeable tabs without ActionBar

I would like to create swipeable tabs without action bar at its top as shown as in the link. I've used the following lines : setDisplayShowHomeEnabled(false);
setDisplayShowTitleEnabled(false);
Also here is my Layout xml.
Can anyone please help me how I can achieve this.
Your layout should be set up similar to this:
<LinearLayout>
<ToolBar/>
<TabBar/>
<ViewPager/>
</LinearLayout>
Also you should choose a theme without ActionBar (i.E. Theme.AppCompat.Light.NoActionBar) for your application, and not call setSupportActionbar()

Android ActionBar design in API greater than 14

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);

How to customize ActionBarSherlock tabs and tab bar

I want to customize ActionBarSherlock tabs and tab bar.It is like this.
I want make it like this
You could use a custom view to display the tabs. You could try a 3-arg LinearLayout constructor (added in API 11). By specifying a default style in an XML file, the library tends to leverage the system layout inflator. So, you can also do a similar work around
<LinearLayout style="?attr/actionBarTabStyle" />
And then add the below code
LineraLayout tabView = LayoutInflater.from(context).inflate(R.layout.my_tab, null);
//set your layout params and setCustomView
Here is two links which will help you to customize ABS.
Customize ActionBar TabBar (ActionBarSherlock)
And
How to customize ActionBar in Android (ActionbarSherlock)?
basically you need to make changes in ABS themes and have to play with its drawable.

ActionBar border won't go away when in overlay

The problem is the following one : on one of my activities, I needed a custom layout for my action bar, and the only way to do it like needed was to have a transparent ActionBar over my screen. In order to do that, I marked the ActionBar as overlay, and specified the action bar background as transparent. This works when using Android >= 15, but in 14 and below, the ActionBar keeps its bottom border. I tried anything to remove it, with no avail.
Here is a picture to see it more clearly :
On API 14 :
On API 16:
The design is the following : the Action Bar is supposed to be transparent and in overlay mode, and behind it there is a background + the logo
<ImageView
android:id="#+id/action_bar_background"
android:layout_width="match_parent"
android:layout_height="#dimen/action_bar_accueil_total_height"
android:layout_alignParentTop="true"
android:contentDescription="#string/action_bar"
android:scaleType="fitXY"
android:src="#drawable/actionbar_logo_extended" />
<ImageView
android:id="#+id/home_gallica_logo"
android:layout_width="#dimen/largeur_logo_carrousel"
android:layout_height="#dimen/action_bar_accueil_total_height"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:contentDescription="#string/action_bar"
android:src="#drawable/logo_fullcolor" />
Some precisions : I use ABS, but this does not seem to be the source of the problem, as switching to the v7 support library did exactly the same thing.
Do anyone has an idea how to remove this bottom border ?
Following the advice and the test by Luksprog in the comment, I used Theme.Sherlock (instead of Theme.Sherlock.Light) in my action bar for this page, and copied from my old theme the settings I needed. This seems to have resolved the problem, but I'm not completely sure of the source. The only advice I can give to people who are going to see this will be to use Theme.Sherlock.
I've tried to make a simple activity to showcase the behavior but I didn't manage to do it. I used an Activity with the theme Theme.Sherlock:
android:theme="#style/Theme.Sherlock
and to make the overlay(in the onCreate() method):
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY); // Window from com.actionbarsherlock.view
//...
setContentView(content);
ActionBar ab = getSupportActionBar();
ab.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
You can hide the action bar at by calling hide() method:
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
Or you can set this in your manifest if you want to hide it permanently:
<activity
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
>

Categories

Resources