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" ...
Related
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);
I've overridden the default blue text selection handles in most of my app by adding these items to the app theme and adding the appropriate 9 patch drawables:
<item name="android:textSelectHandleLeft">#drawable/text_select_handle_left</item>
<item name="android:textSelectHandleRight">#drawable/text_select_handle_right</item>
<item name="android:textSelectHandle">#drawable/text_select_handle_middle</item>
However, this doesn't apply to text selection in a WebView (the blue handles are still there). How can I override the corresponding items in the WebView style?
WebView seems to be referencing the system resources (e.g. android.R.attr.textSelectHandleLeft etc) directly for drawing the handles on its own:
http://src.chromium.org/svn/trunk/src/content/public/android/java/src/org/chromium/content/browser/input/HandleView.java
So, I'd say there's no way to re-style them.
Create your own theme resources and reference them in your Android Manifest.
create your own theme and put it inside res/values
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme">
<item name="android:textSelectHandleLeft">
#drawable/my_own_handle
</item>
<item name="android:textSelectHandleRight">
#drawable/my_own_handle
</item>
</style>
</resources>
refer your own in AndroidManifest.xml.
<application android:theme="#style/MyTheme" >
PS: Referred from crbug: Overriding Selection Controls in Web view
I want to change the color of my actionbar but I'm no good at making image resources so I want to know if there is anyway it is possible to do that without images. like setting a color to some property or something? I surfed a lot but there are too many confusing answers and I can't figure out which one to use.
I am developing for sdk above 8 so I'm using support libraries. Please help.
Generate what ever theme you want from Android Action Bar Style Generator
Copy all the files it generates to the respective folders in res folder and VOILA.. ;)
You could have easily found out the answer here. Or you can click here to create image resources very easily. But anyway, this is how you do it.
first of all, define a color you want for your actionbar in "colors.xml" in the "values" folder of your project like this:
<color name="customColor">#f1f1f1</color>
Then create a new .xml file in your drawable folder with the name say "actionbar_drawable.xml". It has to be a "shape" drawable.
drawable\actionbar_drawable.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid
android:color="#color/customColor"/>
</shape>
Now create "themes.xml" in "values" folder with the following code:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="CustomActionBar" parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle" tools:targetApi="11">#style/CustomBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/CustomBar</item>
</style>
<style name="CustomBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/actionbar_drawable</item>
<!-- Support library compatibility -->
<item name="background">#drawable/actionbar_drawable</item>
</style>
</resources>
Then in your manifest file, set the theme for your activity like this:
android:theme="#style/CustomActionBar"
That's all. Now you won't have to make any image resource. Hope it's helpful to you.
activity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(activity.getResources().getColor(R.color.my_color)));
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.
I use an ActionBarSherlock library in my app. I also needed to customize the ActionBar, so I added a custom theme with a background parameter set, like this:
<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="background">#drawable/action_bar_bg</item>
<item name="android:background">#drawable/action_bar_bg</item>
</style>
action_bar_bg drawable is simply a bitmap of tiled squares:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true"
android:src="#drawable/bg_img_actionbar"
android:tileMode="repeat" />
What I want to do next is to set a linear gradient for a whole ActionBar, so it will cover this background. And I have no idea if it's possible and how to do that.
Any help would be appreciated.
There is a type of resource for this, Shape Drawable:
http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape