How would I position a custom launcher icon set on ActionBar ?
AndroidManifest.xml
<application
android:theme="#style/Theme.AppCompat.Light"
android:allowBackup="true"
android:icon="#drawable/thca_trans"
android:label="#string/app_name">
I would like it to position it with a left margin to stop it from cutting off the left edge of my icon
You can try to create a style for your Action Bar Icon.
<style name="MyActionBarStyle" parent="android:style/Widget.Holo.Light.ActionBarView">
<item name="android:background">#drawable/action_bar_bg</item>
<item name="android:paddingLeft">20dp</item>
<item name="android:paddingRight">20dp</item>
</style>
You can add the above code in your styles.xml.
Or if you cannot solve your problem by the above method and want a totally custom action bar of your own, you can even do so. Take a look at this link for that.
You must create a drawable file containing a "layer-list" like this:
actionbar_logo.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="#drawable/topbar_logo"
android:right="5dp"
android:left="10dp" />
</layer-list>
In yours activity set:
this.getActionBar().setIcon( R.drawable.actionbar_logo);
Related
this is a snip/screenshot of my app design in Adobe Illustrator: https://imgur.com/a/7tXii
Depending on the menu you are currently in, the respective section shall be highlighted as shown below (light blue in this case).
I know that you can change the ITEM/ICON color via a custom ThemeOverlay that you create under /styles.xml and by adding app:theme="#style/afore_mentioned_theme_overlay" like this:
<style name="ThemeOverlay.AppCompat.navTheme">
<!-- Color of text and icon when SELECTED -->
<item name="colorPrimary">#color/color_of_your_choice</item>
<!-- Background color when SELECTED -->
<item name="colorControlHighlight">#color/color_of_your_choice</item>
</style>
However, all this does is change the icon color upon selection, instead of highlighting the section below the icon.
The main problem is, probably, that the navigation background is a horizontal bar along the entire screen, but I just want to change the color of 33% of it, depending on the selected item. This will probably require a dirty workaround (?).
Not that much of a dirty workaround required. Just add this after you initialized your BottomNavigationView instance:
navigation.setItemBackgroundResource(R.drawable.menubackground);
and put this inside /drawable/menubackground.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/colorAccent" android:state_pressed="true" />
<item android:drawable="#color/colorAccent" android:state_checked="true" />
<item android:drawable="#color/colorPrimary" />
</selector>
Looks like this:
My Application uses an Activity (extends AppCompatActivity) with a ListView.
The title-row shows a title and a back-arrow.
A ContextualActionBar is assigned to the ListView.
When the ContextualActionBar gets active, because a long click to one item of the ListView, the back-arrow should be removed.
Please, could anybody give a hint, how to remove the back-arrow of the ContextualActionBar?
Thank You very much!
Best Regards
Uli
It's not really recommended to remove the back arrow, but you can assign it to a transparent drawable
<style name="MyCustomTheme" parent="MyTheme">
<item name="android:actionModeCloseDrawable">#drawable/transparent_drawable</item>
</style>
Where transparent drawable is :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#00FFFFFF"/>
</shape>
and then set it in your manifest
<activity
android:name="MyActivity"
android:theme="#style/MyCustomTheme"
With Holo theme for API level > 14 I retrieve the well kown look with a left margin for the icon in the ActionBar as follows:
<style name="AppBaseTheme" parent="#android:style/Theme.Holo">
When applying Material-theme with AppCompat_v7 support (not changing the code or using the preferred new ToolBar instead) the left margin is missing.
<style name="AppBaseTheme" parent="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
Why and how to fix this ?
As a first workaround I added a Layer List drawable resource named icon.xml to res/drawable/ like this:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="#drawable/ic_launcher"
android:left="20dp"/>
</layer-list>
and referenced this drawable as logo instead of the original icon itself in the AndroidManifest.xml:
<activity
android:logo="#drawable/icon" ...
I am adding an actionbar to a test app I'm writing, and I see questions throughout stackoverflow about this, but nothing that has helped me at all. Based off of this guide:
http://android-developers.blogspot.com/2011/04/customizing-action-bar.html
I'm trying to change the select color for tabs that i'm using on my action bar. The default is that faint blue color. Just as a test I did this:
<style name="CustomTab" parent="android:style/Widget.Holo.Light.ActionBar.TabView">
<item name="android:background">#000000</item>
</style>
That gives me a solid black tab completely, not the selector part. Can someone help better direct me here? I can't seem to find a good example anywhere.
First you have to define a selector xml file then write this code there and replace your code with this
item name="android:background">#drawable/yourfilename</item>
and the selector xml
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:state_pressed="true"
android:drawable="#drawable/picture_selected" />
<item
android:state_focused="true"
android:drawable="#drawable/picture_selected" />
<item
android:drawable="#drawable/picture_unselected" />
</selector>
I'm using the Action Bar for the top of my screen and have buttons there. i'd like an additional sequence of butons at the bottom, but there's too many controls for it to fit in the Action Bar, so I'm creating a Custom View and layout. I'm trying to match the color scheme of hte Action Bar, but I can't figure out what the default Android.R.Color is for the Action Bar.
I've set the custom view's layout as shown. There doesn't seem to be a built in color for light_gray, or anything indicating a menu or action bar default color.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#android:color/darker_gray" />
<stroke android:width="1dip" android:color="#333333"/>
</shape>
you can inspect all the styles by looking at styles.xml in your android SDK platforms folder. e.g.,
<your-sdk-dir>/platforms/android-16/data/res/values/styles.xml
looking at API level 16, this is what i see,
<style name="Widget.ActionBar">
<item name="android:background">#android:drawable/action_bar_background</item>
...
if that resource is not public, your best bet is to set the action bar background and your footer background to something you define. you do this by creating a theme in your styles.xml and overriding the action bar style,
<style name="Theme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
now create the actual action bar style,
<style name="ActionBar" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/my_background</item>
</style>
now assign this style to your application,
<application
...
android:theme="#style/Theme" >
...
I found myself looking for the colors values inside xml files. I couldn't find it. In the end the most stupid idea was the best:
Print screen of emulator and color picker in gimp. This matched exactly the color I've been looking for.
For me this answer is really stupid. However at the end of a day I've been able to find value very quickly.