remove back arrow in ContextualActionBar - android

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"

Related

Highlight the background of the navigation menu item currently selected

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:

How would I position a custom launcher icon set on ActionBar?

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

Trying to color tabs on ActionBar

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>

Retain Default selectableItemBackground in ActionBarSherlock with MenuItem.setActionView

I am using a split ActionBar to display some simple media controls. See Below:
I used MenuItem.setActionView to override the default view for the Fast Forward and Rewind buttons because I need to detect when the user initially touches the control (to start rewinding) and subsequently releases the control (to finish rewinding). See code below:
ImageView rewindButton = new ImageView(getBaseContext());
rewindButton.setId(rewindViewID);
rewindButton.setClickable(true);
rewindButton.setImageResource(R.drawable.ic_action_rewind);
rewindButton.setOnTouchListener(forwardBackwardListener);
MenuItem rewindMenu = menu.findItem(R.id.menu_rewind);
rewindMenu.setActionView(rewindButton);
return true;
This is all working well for me but has had an unintended side effect. When I touch the fast forward or rewind button I do not get the default blue background (as shown on the skip backward control above). It displays no background at all. I tried setting the background in the onTouch handler but the background does not fill the height of the ActionBar in the same way as the default one (see example image below), it seems like there is some padding or margin in place, but I don't know how to remove it.
I have tried the following with no luck:
Setting the height of the ImageView Manually to try to fill the ActionBar
Returning True or False from the onTouch Handler
Does anyone know how I might resolve this?
I came up with a workaround which was to set the background of all the items to a small radial gradient when the item is selected. The gradient is still cut off a little but it is hardly noticeable. It makes the custom and regular buttons look almost the same.
First I created the radial gradient in a file called res/drawable/radialbackground.xml . Notice the end color is transparent, this is important to fade the gradient into nothing so it doesn't fill the whole rectangle.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:centerX="0.5"
android:centerY="0.5"
android:endColor="#00FFFFFF"
android:gradientRadius="35"
android:startColor="#color/Gray"
android:type="radial"
/>
</shape>
Then I created a StateListDrawable called res/drawable/actionitembackground.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="#android:integer/config_mediumAnimTime" >
<item android:state_pressed="true" android:drawable="#drawable/radialbackground" />
<item android:drawable="#android:color/transparent" />
</selector>
Then I assigned that statelistdrawable to the backgrounds of my custom ActionViews :
rewindButton.setBackgroundResource(R.drawable.actionitembackground);
Then I altered the style for the actionbar to include this new radial fill for the regular action bar items.
So, in values/styles.xml I added:
<style name="Theme.MyTheme" parent="Theme.Sherlock.Light">
<item name="android:selectableItemBackground">#drawable/actionitembackground</item>
<item name="selectableItemBackground">#drawable/actionitembackground</item>
</style>
In my case, the base style was Theme.Sherlock.Light but you would replace that with whatever style you wanted to amend.
Then I set that style as the style for my application in AndroidManifest.xml
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.MyTheme"
android:uiOptions="splitActionBarWhenNarrow" >
This seemed easier than digging through trying to debug why the background is cut off. Perhaps I will spend more time on it another day.
I had exactly the same problem, but with a spinner on action bar,
you need to set de minHeight of yout view to actionBar height:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/drop_down"
android:minHeight="?android:attr/actionBarSize"
>
<Spinner
android:id="#+id/category_spinner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/default_selector"
android:minHeight="?android:attr/actionBarSize"
android:gravity="center_vertical|right"
android:paddingRight="5dp"
/>

how to change button color when it is clicked in android

By default when button is clicked something like orange color will surround the button for short time, that indicates buttons is clicked. But this feature is not working when button contains background image. This is happening in list view too.why ? Any Ideas? TIA
I used setBackgroundColor(Color.BLUE); But here the color is applied and not gone...
You need to use a selector as your background resource :
<?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/button_pressed" />
<item android:state_focused="true" android:drawable="#drawable/button_focus" />
<item android:drawable="#drawable/button_normal" />
</selector>
This selector makes use of 3 separate drawables to change the image of the button , you may use the same image for pressed and focuses.
You need to put this XML into your drawables directory and use it as a background for your button.
For another solution refer : Standard Android Button with a different color
i too had the same problem. so instead of setting the background color,i included three images of button in three different colors , so based on state focused,pressed,default the respective image will replace the other. and it looks like change in the color of the button.
**<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/c2"
android:state_pressed="true" />
<item android:drawable="#drawable/c1"
android:state_focused="true" />
<item android:drawable="#drawable/c1" />
</selector>**
above is the content of the xml file,which must be assigned to the background of the respective button
android:background="#drawable/drawable_button
hope this might be helpful for you

Categories

Resources