Action bar with text in the middle of it that is clickable - android

I am trying to do in my app that i will have a clickable text in the middle of the actionbar like the whatsapp app have ,
In this picture you will see in the actionbar it got details of the person and its clickable , that is the exactly thing i am looking for
I saw that i can add subtitles and ofcourse the main title of the actionbar but i didnt seem to find a good result for that exact thing
Thanks heads up :)

Add TextView as CustomView that will mimic the plain title and at the same time clickable, instead putting it with setTitle(). Add click listener to the TextView before you supply it to the ActionBar. Don't forget to stretch to the size of the ActionBar.
Hope this idea helps.
Edit:
To get the same appearance in terms of size of text of the title and subtitle look at styles.xml
<style name="TextAppearance.Widget.ActionBar.Title"
parent="#android:style/TextAppearance.Medium">
</style>
<style name="TextAppearance.Widget.ActionBar.Subtitle"
parent="#android:style/TextAppearance.Small">
</style>
<style name="TextAppearance.Medium">
<item name="android:textSize">18sp</item>
</style>
<style name="TextAppearance.Small">
<item name="android:textSize">14sp</item>
<item name="android:textColor">?textColorSecondary</item>
</style>

use this way:
ActionBar action = getSupportActionBar();
action.setHomeButtonEnabled(true);
action.setDisplayShowTitleEnabled(true);
action.setTitle("Title");
action.setSubtitle("Sub title");
action.setIcon(getResources().getDrawable(R.drawable.ic_launcher));
for < 11 Android API use actionbarsherlock
or you can also use custom layout for actionbar and actionbar item click.
https://stackoverflow.com/a/7981633/1168654

Related

Overlay or hide Toolbar on copy/cut selection

I've created an activity with the new Appcompat v21 Toolbar. Everything works fine except when I highlight some text out of a TextView. The copy/cut Actionbar shows up, but instead of overlaying my existing toolbar or hiding it it just pushes the toolbar down so I get something like this:
Now my question is, how can I make the copy/cut actionbar overlay my toolbar? Or should I just hide it if text is selected? If so, how do I listen for textselection?
Best regards
in your theme you need to add this to it
<item name="windowActionModeOverlay">true</item>
so it would look something like this
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/color_primary</item>
<item name="colorPrimaryDark">#color/color_primary_dark</item>
<item name="colorAccent">#color/color_primary</item>
<item name="windowActionModeOverlay">true</item>
</style>

How to customize actionbar navigate home button

<style name="MyActionBar.ActionBarStyle" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/button_style</item>
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
The upper one is default , when i clicked it's background color seem like it. But i want it's background seems like as second.
Hi check this ActionBar Style Generator in Github ActionBar Style Generator . Hope it will help you. :)

change the actionbar text color of an item

trying to change actionbar text color of this item in the action bar. here is the item
<item android:id="#+id/options_button"
android:title="#string/options"
android:showAsAction="ifRoom|withText"/>
and here is my styles.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="MyCustomTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBarTheme</item>
<item name="android:background">#color/White</item>
<item name="android:textColor">#color/Red</item>
</style>
<style name="MyActionBarTheme" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/White</item>
<item name="android:textColor">#color/Red</item>
</style>
</resources>
i saw other posts on here about this but after trying their solutions nothing worked for me? is it something to do with how i made the theme? All i really wanted was my action bar to be white, not display the title, and display a button that says options. I have all of that, but the options I want to be a red color im working with rather than black.
dont think people understand...
I know of the way to change the title (I dont have a title and i dont want one).I want to change the color of the item that is displaying itself in the actionbar...
I have faced the same issue, but I found a solution that doing well with any type of ActionBar (Native, Sherlock or Compat)
Actually you can use HTML code to set the title, and specify the text color. For example, to set the ActionBar text color to red, simply do this:
getActionBar()/* or getSupportActionBar() */.setTitle(Html.fromHtml("<font color=\"red\">" + getString(R.string.app_name) + "</font>"));
You can also use hex code of red color #FF0000 instead of the word red.
But, Setting a HTML string on the action bar doesn't work on the Material theme in SDK v21+.
If you want to change it you should set the primary text color in your style.xml as below.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material.Light">
<!-- Customize your theme here. -->
<item name="android:textColorPrimary">#color/actionbar-text-color</item>
May this helps you.

Actionbar tabs don't fill the tabbar

After hours of trying I finally found a method to separate the actionbar tabbar from the actionbar manualy.
actionbar convert tabs to list navigation if there is no room
But now there is one problem left. The tabs don't fill the tabbar.
EDIT
The tabs are added to the actionbar by:
ActionBar.Tab relatieTab = actionBar.newTab().setText("Relaties");
actionBar.addTab(relatieTab);
Try to switch the parent. If that doesn't work try visiting this post: Stacked ActionBar tab bar not filling parent
Good luck :)
Use the following to customize the tabs in action bar:
<style name="MyAppActionBarTabStyle" parent="#android:style/Widget.ActionBar.TabView">
<item name="android:background">#drawable/actionbar_tabindicator</item>
<item name="android:minWidth">40dip</item>
<item name="android:maxWidth">40dip</item>
<item name="android:layout_width">0dip</item>
<item name="android:layout_weight">1</item>
</style>
Make sure that the activity where you are setting these navigation tabs has the following in its #android:theme
<style name="MyAppTheme" parent="android:style/Theme.Holo.Light">
<item name="android:actionBarTabStyle">#style/MyAppActionBarTabStyle</item>
</style>
I still could not figure how how to detect whether the tabbar is separate i.e. below main action bar or merged (when in landscape OR larger screens even in portrait)
Another interesting thing to know is how to prevent tab bar from collapsing to a spinner when space is not enough.
As and when I find out answers to my questions above, will update the post. Until then hope the styles help few other ppl
I just solved this problem today.
They key was using <item name="android:padding">0dp</item> like so...
<style name="MyActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar">
</style>
<style name="LoginActionBar"
parent="#style/MyActionBar">
<item name="android:actionBarTabStyle">#style/LoginActionBarTabs</item>
</style>
<style name="LoginActionBarTabs"
parent="#android:style/Widget.Holo.ActionBar.TabView">
<item name="android:padding">0dp</item>
</style>
You don't need that many styles, but I didn't want to take any chunks out, which may have lead to confusion.
I also see that you already worked around this, but I figured I'd add my answer for the next person to come looking for this.

Android how to style a SearchView in Actionbar?

I need to change the style of my SearchView in my ActionBar. In particular I need to change the text hint color and the SearchView icons if possible. How can I accomplish this in XML (is it even possible in XML)?
If this isn't possible, how can I easily recreate similar behavior with a custom view? The close/expand behavior of the SearchView is particularly useful for me.
Have you tried something like this (With ActionBarSherlock):
AutoCompleteTextView searchText = (AutoCompleteTextView) searchView.findViewById(R.id.abs__search_src_text);
searchText.setHintTextColor(getResources().getColor(R.color.white));
searchText.setTextColor(getResources().getColor(R.color.white));
It works fine for me.
It looks like you may need to supply a custom layout for your search action. I haven't been able to find any documents that talk about modifying the default SearchView. But this does allow the close/expand behavior.
http://developer.android.com/guide/topics/ui/actionbar.html#ActionView
Related questions:
Honeycomb - customize SearchView inside the action bar
set numeric input type to SearchView in ActionBar
You need to create a new theme and use it in manifest file.
<style name="Theme.Test" parent="#style/Theme.AppCompat.Light">
<item name="searchViewAutoCompleteTextView">#style/Theme.Test.SearchField</item>
</style>
<!-- Search edit text -->
<style name="Theme.Test.SearchField" parent="#style/Widget.AppCompat.Light.AutoCompleteTextView">
<item name="android:textColor">#color/white</item>
<item name="android:textColorHint">#color/white</item>
</style>
It worked fine for me.
The right answer is to overload the action bar widget style with your own custom style. For holo light with dark action bar, put this in your own styles file such as res/values/styles_mytheme.xml:
<style name="Theme.MyTheme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarWidgetTheme">#style/Theme.MyTheme.Widget</item>
<!-- your other custom styles -->
</style>
<style name="Theme.MyTheme.Widget" parent="#android:style/Theme.Holo">
<item name="android:textColorHint">#android:color/white</item>
<!-- your other custom widget styles -->
</style>
Make sure your application is using theme custom theme as described in enter link description here

Categories

Resources