Transparent of Android Contextual Action Bar - android

A contexual action bar(CAB) will be shown when long tapping at TextEdit on Andriod WebView.
I specified the following styles, in order to avoid that a layout breaks, but menu doesn't became transparent and hide TextEdit. What should I write with this menu for making it transparent?
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Holo">
<item name="android:actionBarStyle">#style/AppStyle</item>
<item name="android:windowActionModeOverlay">true</item>
</style>
<style name="AppStyle" parent="android:Widget.Holo.ActionBar">
<item name="android:colorBackground">#00000000</item>
</style>
</resources>

Create a resource for your colors and reference them from there:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<color name="transparentBlack">#00000000</color>
</resources>
Change the AppStyle to this:
<style name="AppStyle" parent="android:Widget.Holo.ActionBar">
<item name="android:background">#color/transparentBlack</item>
</style>
The main difference is background vs colorBackground, I'm not really sure if there is a functioning difference, but I know that when I compare my working transparent action bar style and your action bar style that is pretty much the only difference.
You could try to change only the android:colorBackground to android:background and see if that alone works, but I've found it best to use references instead of hard coding colors directly. If you are curious to change only one, try them separately to see if they solve your problem.
NEW SUGGESTION AS OF 12.22.2014-
Why don't you just hide the action bar (mSpecialActionBar.hide();) and then implement a View.OnLongClickListener for your Activity. You can then show the action bar again (mSpecialActionBar.show();) on a long click. Or something similar.
#Override
public void onLongClick(View v) {
if (v.getClass() == TextEdit) {
mSpecialActionBar.show();
}
} // end-of-method onLongClick
Here is a resource I found useful: http://java.dzone.com/articles/contextual-action-bar-cab

Related

Changing the Color of the the Menu Items does not work

I have created a menu and now I want to change the text color of the individual menu titles.
To do this, I first created a style that should contain the corresponding attribute and then called this style in my Activity_home_drawer.xml. However, this only changes the menu TextColor when the corresponding menu title is clicked but is not permanent as I would like it to be.
What do I have to do so that the text color in my menu changes permanently to white and not Black anymore? Is my way of doing it the right way or is there a more elegant way to change the TextColor?
Thanks for any help!
Part of my Activity_home_drawer.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view"
android:theme="#style/TextAppearance44">
<group android:id="#+id/category_group">
<item
android:id="#+id/nav_menu"
android:icon="#drawable/ic_store_black_24dp"
android:title="#string/menu_menu"
android:theme="#style/TextAppearance44"
/>
</group>
My TextAppearance44 style
<style name="TextAppearance44">
<item name="android:textColor">#color/colorWhite</item>
<item name="android:actionMenuTextColor">#color/colorWhite</item>
<item name="android:textSize">16sp</item>
<item name="android:titleTextColor">#color/colorWhite</item>
</style>
You need to change your ToolBar style. Check these two tutorials:
Toolbar assigning to activity and styling:
https://android-developers.googleblog.com/2014/10/appcompat-v21-material-design-for-pre.html?m=1
Changing style and items colors in the Toolbar:
https://www.murrayc.com/permalink/2014/10/28/android-changing-the-toolbars-text-color-and-overflow-icon-color/
In your case, you are looking mainly for (code fragment from second tutorial):
<!-- android:actionMenuTextColor is the color of the text of
action (menu) items in the Toolbar, at least in the
Theme.AppCompat theme.
For some reason, they already get the textColorPrimary
when running on API 21, but not on older versions of
Android, so this is only necessary to support older
Android versions.-->
<item name="actionMenuTextColor">#color/abc_primary_text_material_light</item>
I solved it by myself; I added these to lines to my NavigationView in my ActivityHome (where the Menu comes up).
app:itemTextColor="#color/colorWhite"
app:itemIconTint="#color/colorWhite"
Simple mistake, didnot know that there was such a attribute.

How to add image instead of title text in android

I want to add this image instead of title text and default android image of action bar, like shown in image above.
From what I've tried for this matter, You can do it by making one layout that will act as the action bar, and then call it in every activity you have and set your Manifest. Here I give you clue on it and how to set it in manifest and your activity class:
Code your 'action bar layout', let's call it window_header.xml. Put it in your res>layout directory. Just make a layout that contain an imageview, set the layout's height as it will be your action bar height.
You can also set the color and everything you want, just make it like a normal layout with the height you set.
In your Manifest, in the android:theme section, change it to looks like this:
android:theme="#style/CustomTheme"
To accomplish it, you need a resource file which stating that it will use a custome style, here is my code of it:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomWindowTitleBackground">
<item name="android:background">#323331</item>
</style>
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">35dip</item>
<item name="android:windowTitleBackgroundStyle">#style/CustomWindowTitleBackground</item>
</style>
</resources>
And lastly, call it in your activity OnCreate method like this:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_header);
ImageView icon = (ImageView) findViewById(R.id.icon);
this.icon.setImageResource(R.drawable.browse);
Try it, a little bit of exploration and self inovation would done better. Hope it helps

set actionbar icon height to match actionbar height

see the problem here, the grey checkbox leaves room from the top and bottom of the action bar:
styles.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomActionBarTheme" parent="Theme.Base.AppCompat.Light">
<item name="android:windowContentOverlay">#null</item>
<item name="android:actionButtonStyle">#style/ActionButtonStyle</item>
</style>
<!--<style name="ActionButtonStyle" parent="#android:style/Widget.Holo.Light.ActionButton">-->
<style name="ActionButtonStyle" >
<item name="android:height">#dimen/abc_action_bar_default_height</item>
<item name="android:layout_height">#dimen/abc_action_bar_default_height</item>
</style>
i set the item like so:
getMenuInflater().inflate(R.menu.submit_action, menu);
submit_action looks like:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/action_submit"
android:icon="#drawable/check"
app:showAsAction="always" />
</menu>
and finally, attached is the #drawable/check being used.
any idea how i can get the check to fill the actionbar?
The reason your icon doesn't fill the ActionBar is due to how the ActionMenuItemView measures the icon.
The ActionMenuItemView invokes a maximum size of 32dp when it sets the bounds for your icon
So, it makes so difference how large your image is, the system will always resize it.
any idea how i can get the check to fill the actionbar?
You should use a action layout for your MenuItem, a check mark icon with no background, and change the background color of the action layout parent as you see fit. Here's an example:
layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/actionButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#e8e8e8"
android:clickable="true"
android:contentDescription="#string/cd" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#null"
android:scaleType="centerInside"
android:src="#drawable/ic_action_tick" />
</RelativeLayout>
MenuItem
<item
android:id="#+id/action_submit"
android:actionLayout="#layout/your_action_layout"
android:showAsAction="always"/>
Accessibility
It's important to make sure your MenuItem is accessible. Normally when you long press an item in the ActionBar a short Toast will display the content description for you, but when you're using a custom MenuItem it's up to you to implement this pattern. An easy way to do this is by using Roman Nurik's CheatSheet. If you're unsure how to use it, you should refer to my answer here that goes into much more detail on creating custom MenuItem layouts.
Alternatively
If you want to use that background color for every MenuItem you have, you could create a custom style and apply it using the android:actionButtonStyle attribute. Here's an example of that:
Your style
<style name="Your.ActionButton" parent="#android:style/Widget.Holo.Light.ActionButton">
<item name="android:background">#e8e8e8</item>
</style>
Your theme
<style name="Your.Theme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionButtonStyle">#style/Your.ActionButton</item>
</style>
Results
Here's what I do with Icons in Android to get the sizing correct. You have an existing project with the res/drawable- folders. You have to put the correct Icon into the correct folder.
Start a new project wizard and when you get to the launcher icon put in the Icon you want to use in your existing project. finish the wizard. The wizard will make the various sizes of Icons for you. Then I manually copy the Icons from the res/drawable-xdpi res/drawable-ldpi etc to the corresponding folder on my existing project. Delete the new project it is no longer needed.

ActionBar default 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.

Android Is it possible to use menu with themes

In my app the user can choose from 4 different themes. The time has come to create different menu icons for the different themes, but the icons do not show in the menu items. Any ideas?
Menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/Menu1"
android:orderInCategory="1"
style="?menu_addtolist" />
attrs.xml
<attr name="menu_addtolist" format="reference" />
themes.xml
<item name="menu_addtolist">#style/menu_green_addtolist</item>
styles.xml
<style name="menu_green_addtolist">
<item name="android:src">#drawable/menu_addtolist_green</item>
</style>
I did everything the way I had done with the other objects (buttons, layouts, texts). When I select a theme, the full theme changes, but there are no menu icons.
I changed the style in the menu item to another one I use in the app as a button style, and that did not make a change, while that style is definitely working. Maybe it is not possible to apply styles to menu items?
It looks like the answer is no. It is not possible to use themes with menu. Maybe because the menu has no (available) layout

Categories

Resources