Removing icon from BottomNavigationView - android

I want my menu items on the BottomNavigationBar to have text-only labels with no icon. Unfortunately, it looks like design_bottom_navigation_item.xml always has a 24x24dp space reserved for the icon, with no publicly-exposed way to set it to gone. And even after getting past that, the label layout is set to a layout_gravity of bottom|center_horizontal, and it doesn't look like there's a way to programatically set layout_gravity to centered.
What is the fastest, easiest way to achieve the goal of a text-only menu item on the bottom nav bar? I'm thinking I can do this by creating a custom version of the item layout, then subclassing BottomNavigationItemView, BottomNavigationMenuView, and BottomNavigationView to specify that custom layout... but that seems like an awful lot of work for one little change. Am I missing something simpler?

dont put iandroid:icon property to your item

Just use the code below. I tried hard to do this easy way but failed.Then I made an alternative. Just use transparent color instead of icon drawble
<item
android:icon="#android:color/transparent"
android:id="#+id/navigation_id"
android:title="title" />

Add this in your dimens file. Then you can add padding according to your navigation view size.
<dimen name="design_bottom_navigation_height"tools:override="true">30dp</dimen>

Related

Remove RadioButton Icon Android

Is there a way to totally remove the Icon from a RadioButton?
I'm bolding the text instead of using the icon.
Setting android:button to either #null or #android:color/transparent
only hides the button and still messes up my test positioning.
I suppose that I could use a dummy view that's only 1dip big, but I wanted to check if there was less of a hack.
Try setting the background and button to #null.
set android:button="#null" will remove the default radio icon

Overlapping views crossing boundaries (Fake actionbar)

I am trying to create a custom title bar strictly for Android 2.1 that somewhat emulates the ActionBar found in Android 3.0 and up.
So far I've had fairly decent luck, but I cannot find an easy way to make the drop-down lists that can appear below the icon / buttons in the ActionBar.
I would like these drop-down lists to be able to cross the boundary between the title layout and the content layout without being clipped / cut off. I would also like the drop-down lists to be positioned relatively below the icons / buttons in the ActionBar. I've seen advice to use FrameLayouts and RelativeLayouts already but these did not seem to solve my particular problem (unless I'm looking at it wrong). I keep thinking it must be possible since I believe the newer versions of Android have support for exactly this type of behavior.
Here is a screenshot of what I am trying to accomplish with some notes.
http://img217.imageshack.us/img217/3279/67343249.png
Please help. Thanks!!!
I think best way to do that is to create a linear layout and add your drop-down list item into that linear layout. Then add linear layout on button click and display it just below to the button by using relative layout layoutparams.
You need to hold your content with a FrameLayout. A FrameLayout can hold more than one child, and it will allow them to overlap on each other.
A possible layout xml could look like:
<FrameLayout>
<LinearLayout android:margin_top="30dip">...</LinearLayout>
<CustomActionBar />
</FrameLayout>
The 30dip is just the height of your ActionBar, you might want to define it in values. And the LienarLayout you can replace with anything which is just for holding the other content in your application.
PS. I am not sure if FrameLayout renders first child first or last. In case you found the linearlayout stuff overlaps the customactionbar, swap their position.
=== Edit ===
To make the code much cleaner, one can do in this way:
<CustomActionBar>
<LinearLayout/>
</CustomActionBar>
Which replaced the custom action bar to be the "root" element of any xml layout that utilized the action bar. When doing the custom action bar, you need to extend it from FrameLayout, and assign the child's margin accordingly. Which the idea is much the same as the one I presented above.
After a few days of research I found the best way to implement this is to use a custom dialog box with a custom theme that contains a listView. When the user clicks on the button the dialog should be displayed directly below the button. This provides a good user experience and also means you don't have to completely change your basic layout structure to accomodate this functionality. (This is basically the same approach that ActionBar Sherlocke uses for their backwards compatibility menus)
Here is a code snippet of what I'm describing (this is written in C# using Mono for Android but it should be easy to translate to Java):
Dialog dlgHome = new Dialog(this, Resource.Style.ActionBarMenu);
dlgHome.SetCanceledOnTouchOutside(true);
dlgHome.SetContentView(Resource.Layout.ActionBarMenu);
ListView lsvHome = (ListView)dlgHome.FindViewById(Resource.Id.lsvHome);
lsvHome.Adapter = new ArrayAdapter<string>(this, Resource.Layout.ActionBarMenuItem, new string[] { "Add Activity", "Edit Log", "Program Details" });
Rect r = new Rect();
btnHome.GetLocalVisibleRect(r);
int x = r.Left + (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 5, Resources.DisplayMetrics);
int y = r.Bottom;
WindowManagerLayoutParams param = dlgHome.Window.Attributes;
param.Gravity = (int)(GravityFlags.Top | GravityFlags.Left);
param.X = x;
param.Y = y;
dlgHome.Window.Attributes = param;
Also, here is the style xml (goes in style.xml)
<style name="ActionBarMenu" parent="android:Theme.Dialog">
<item name="android:windowBackground">#color/actionbar_menu_bg</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>

How to remove Fading effect from Listview?

In my application I use a ListView and I need to remove the cacheColorHint at the bottom and top of the list. I tried to set the cacheColorHint to #00000000 but the have semi-transparent effect at the bottom/top.
Do you if it is possible to remove these effect?
Thanks
I think the problem is not with cacheColorHint. Maybe you are trying to deal with fading edge attribute of the listview.
Add this attribute to your listview and check it out,
android:fadingEdge="none"
EDIT
This attribute is deprecated and will be ignored as of API level 14 (ICE_CREAM_SANDWICH). Use android:fadingEdgeLength="0dp" instead. (from Zsolt Safrany's comment).
Take a look at this great article of Romain Guy: http://www.curious-creature.org/2008/12/22/why-is-my-list-black-an-android-optimization/
However to disable the optimization, simply use the transparent color #00000000 for the cacheColorHint, as you are doing, and set a solid background color on the ListView to replace its default semi-transparent background.

How to remove selected color on drag over listview

I am displaying a ListView. When I drag over it, the entire ListView is selected with a black background. How can I remove that black background?
just use in ur xml file inside ListView,
android:cacheColorHint="#android:color/transparent"
It's probably because you have a custom background for your ListView. When you scroll those, the entire list gets highlighted in a black color due to its cache color.
Add this piece of code to your ListViewand try again:
android:cacheColorHint="#00000000"
view.setBackgroundColor(android.R.color.transparent);
should be view.setBackgroundResource(android.R.color.transparent)
cause setBackgroundColor take a hex color value as parameter.
or
android:cacheColorHint = "#00000000"
use this tag for the your listView. or you can also use
listview.setCacheColorHint()
to set it programatically.
From Why is my list black? An Android optimization on the Android developers' blog:
To fix this issue, all you have to do is either disable the cache color hint optimization, if you use a non-solid color background, or set the hint to the appropriate solid color value. This can be dome from code or preferably from XML, by using the android:cacheColorHint attribute. To disable the optimization, simply use the transparent color #00000000. The following screenshot shows a list with android:cacheColorHint="#00000000" set in the XML layout file:
use this,
yourList.setCacheColorHint(Color.WHITE);

Android how to make View highlight when clicked?

I have a linear layout in which each row is inflated programatically and I want the rows to behave like the ListView when clicked on. That is, I want the row to highlight in the exact same way/colour that the default ListView does. How would I go about doing this?
Ok I have finally figured out how to do this...basically it is done using a selector like the color selector linked by style except instead of 'color' use a drawable for the states and you can refer to the default list drawable that is used in ListView by this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="#android:drawable/list_selector_background" />
</selector>
and using this xml as the background for my View.
All the public default drawables can be found here: http://developer.android.com/reference/android/R.drawable.html
I was able to do the same with a text view that I wanted to behave like a list item by using:
<Textview
....
android:background="#android:drawable/list_selector_background"
/>
This might be a good place to start looking.
Although, i would advise you to use the ListView itself, rather than implementing it again.
if you still have a problem with that then please remember that some of UI elements are not clickable (RelativeLayout), so you have to add one more line:
<RelativeLayout
....
android:clickable="true"
...
To your listview set property
android:listSelector="#color/test"
and this test color set any transparent color you like. you can create any transparent color by using hex transparent color

Categories

Resources