How to disable the line divider in the navigation menu? - java

I want to disable the line divider in my navigation menu. I tried a code out, but it doesnt worked. I hope someone can help me :)
That is the code that I tried:
<item name="android:listDivider">#android:color/transparent</item>

Ok you have to add the Style :
<item name="android:listDivider">#android:color/transparent</item>
but you have to define it as background in your divider view :
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/listDivider"/>
</FrameLayout>

Related

First item in bottom navigation bar is not visible

First item in bottom navigation bar is not visible, although its clickable and working properly.
Tried the solutions given to this question: KOTLIN - First item in BottomNavigationBar isn't visible, title issues
But nothing seems to work out.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MapsActivity">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="#color/white"
app:itemIconTint="#drawable/selector"
app:itemTextColor="#drawable/selector"
app:labelVisibilityMode="labeled"
app:menu="#menu/nav_menu" />
This is the code in my xml file regarding the bottom navigation bar.
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Information"
android:id="#+id/information_nav_bar"
android:icon="#drawable/ic_info" />
<item android:title="Table"
android:id="#+id/table_nav_bar"
android:icon="#drawable/ic_info" />
This is my navigation menu xml.

Display icons with text in toolbar

How can i display icons along with text in Bottom navigation of Android.
Many thanks!
click here to view the image
That looks like a CardView wrapping a BottomNavigationView.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="24dp"
android:layout_gravity="bottom"
android:layout_margin="16dp">
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="#menu/menu_main"/>
</android.support.v7.widget.CardView>
</FrameLayout>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/lorem"
android:icon="#drawable/ic_archive"
android:title="Lorem"/>
<item
android:id="#+id/ipsum"
android:icon="#drawable/ic_archive"
android:title="Ipsum"/>
<item
android:id="#+id/dolor"
android:icon="#drawable/ic_archive"
android:title="Dolor"/>
</menu>
You can replace icon from menu with your own png Icons heaving text. And will leave title remain empty. Its tested Technique!

Change color of navigation bar selected item

I used
setTheme(R.style.Theme_AppCompat);
to set my app theme darker.
Now I run into that issue that the selected item in my navigationbar is relativly dark, so that users can hardly see it.
Is there anything that I can use in my style to get the selected navigation item in another color?
Here is a picture of it
Here is my activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
tools:context="at.mrminemeet.asciimoji.MainActivity">
.....
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="#menu/navigation"/>
</android.support.constraint.ConstraintLayout>
Add the following to your BottomNavigationView:
app:itemIconTint="#drawable/bottom_navigation_selector"
app:itemTextColor="#drawable/bottom_navigation_selector"
In your drawable folder, create a file bottom_navigation_selector.xml and add this to it:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns :android="http://schemas.android.com/apk/res/android">
<item android:color="#color/colorAccent" android:state_checked="true"/>
<item android:color="#android:color/darker_gray" android:state_checked="false"/>
</selector>
Finally in every activity where you use this navigation bar add this line to onCreate() and onResume()
bottomNavigationView.setSelectedItemId(R.id.item);
You can specify the BottomNavigationView_itemBackground attribute to your BottomNavigationView, you can set a selector as a background with different colors for the normal and selected states

Layout margin pushing image in ImageView

I am using grid view to display images in my app and I am using CardView for parent element.
I want the CardView to have some space from the beggining of the page and between each CardView so I am setting layout_margin to be 5dp.
I also want to have some space between the image and the beggining of the CardView so I put contentPadding to be 10dp.
The result though is not what I want. It seems that the layout_margin is pushing the image itself and the padding for the right side is not 10dp as I want but 10dp - 5dp and I really have no clue how to fix that
Here is visual examples:
And this is the result I get:
You can see the right side of the CardView and how the image is not properly centered.
Thank you for your help!
Edit:
ImageViewStyle:
<style name="ImageViewStyle">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">#dimen/card_view_image_view_height</item>
<item name="android:layout_gravity">center</item>
<item name="android:layout_alignParentTop">true</item>
<item name="android:scaleType">centerCrop</item>
</style>
Try this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_margin="5dp"
app:cardCornerRadius="2dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="10dp"
android:background="#drawable/image"/>
</android.support.v7.widget.CardView>

android add button to title bar

I am trying to add a button to title bar but I couldn't succeed. I have read many articles about this but they all explain the way that doesn't fit my situation. I am using ScrollView to make the screen scrollable. but articles suggest me to use linear layout. How can I make it scrollable and have a button on the title bar?
here is my XML
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#C0C0C0"
android:id="#+id/sw_layout">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:id="#+id/ln_layout">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft=<"#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" >
.........................
.........................
.........................
</TableLayout>
</LinearLayout>
</ScrollView>
And in my MainActivity, I have this code....
LinearLayout ln = (LinearLayout) getWindow().findViewById(R.id.ln_layout);
Button btn = new Button(this);
btn.setText("Test");
ln.addView(btn);
But this doesn't display anything and it doesn't give me any error. Please give me an idea. how can I add the button to title bar?
make title.xml and design your title : place button etc
on activity
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
you will access to elements on title the same way you do on main layout .using findviewbyid
for avoiding some look problems
<style name="theme">
<item name="android:windowTitleBackgroundStyle">#style/themeTitleBackground</item>
<item name="android:windowTitleSize">65dip</item>
</style>
<style name="themeTitleBackground">
<item name="android:layout_height">wrap_content</item>
</style>
inside androidmanifest
<activity android:theme="#style/theme"

Categories