Example
Here's an example of what I'm asking about. I don't know the name of this gray circle that appears when I click, but I need to make it smaller. Please, help.
My BottomNavigationView:
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigationView"
app:menu="#menu/bottom_nav_menu"
app:itemTextColor="#color/bottom_nav_color"
app:itemIconTint="#color/bottom_nav_color"
android:outlineProvider="none"
app:labelVisibilityMode="labeled"
app:itemIconSize="40dp"
android:layout_width="match_parent"
android:layout_height="65dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
My bottom_nav_color.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="#color/black" />
<item android:state_checked="false" android:color="#color/black"/>
</selector>
Related
I need to get such result as here
I tried do like this :
my bottom_nav_menu_bg
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/home_btn_bg" android:state_checked="true" />
<item android:drawable="#color/gray_900"/>
</selector>
My BottomNavView
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_menu"
android:layout_width="match_parent"
android:layout_height="90dp"
android:layout_weight="1"
app:itemBackground="#drawable/bottom_navigation_menu_bg"
android:background="#color/gray_900"
app:menu="#menu/bottom_navigation"
app:itemIconTint="#drawable/tab_color"
app:itemTextColor="#drawable/tab_color"
android:backgroundTint="#null"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
/>
my home_btn_bg for getting gradient color
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#color/black"
android:endColor="#color/light_green_100"
android:angle="90" />
</shape>
but i got smth like that :
I use bottomNavigation.
I wanna fill the icon with the color "not the outside of the icon" when selected.
How can I do that?
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="56dp"
android:paddingTop="2dp"
android:background="#FFFFFF"
android:theme="#style/BottomNavigationTextStyle"
app:labelVisibilityMode="labeled"
app:itemIconSize="24dp"
android:layout_alignParentBottom="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:menu="#menu/buttom_navigation_menu">
</com.google.android.material.bottomnavigation.BottomNavigationView>
Use the itemIconTint attribute:
<com.google.android.material.bottomnavigation.BottomNavigationView
app:itemIconTint="#color/my_selector"
..>
and define a selector like:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="1.0" android:color="..." android:state_checked="true"/>
<item android:alpha="0.6" android:color="..."/>
</selector>
Use custom made images as per your requirement. You would need to add 2 images one for the active state and for deactive state.
Create a selector home_icon_selector.xml for your icon
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/your_active_icon_here" android:state_selected="true" />
<item android:drawable="#drawable/your_active_icon_here" android:state_pressed="true" />
<item android:drawable="#drawable/your_active_icon_here" android:state_checked="true" />
<item android:drawable="#drawable/your_deactive_icon_here" />
</selector>
Update your menu buttom_navigation_menu to use the selector above
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/menu_home"
android:enabled="true"
android:icon="#drawable/home_icon_selector"
android:title="#string/tab_title_home"/>
</menu>
I spent almost the whole weekend to figure out how to create a table structure with headers for columns and rows and include ImageButtons in the cells of the table. The grid lines should be visible.
I tried lot of different layouts... Grid, Linear, Structured, CoordinatorLayout .... view nested GridViews and so on. But couldn't figure out how to accomplish something like this?
Some kind of nested layout magic?
Create a drawable cell_shape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape= "rectangle" >
<stroke android:width="0.5dp" android:color="#4E4E4E"/>
</shape>
In your styles.xml define your custom cell style
<style name="Cell">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_weight">1</item>
<item name="android:background">#drawable/cell_shape</item>
<item name="android:gravity">center</item>
<item name="android:paddingTop">8dp</item>
<item name="android:paddingBottom">8dp</item>
<item name="android:textSize">12sp</item>
</style>
table_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<TextView
style="#style/Cell"
android:text="\"
android:textStyle="bold" />
<TextView
style="#style/Cell"
android:text="My Title 1"
android:textStyle="bold" />
<TextView
style="#style/Cell"
android:text="My Title 2"
android:textStyle="bold" />
<TextView
style="#style/Cell"
android:text="My Title 3"
android:textStyle="bold" />
</TableRow>
<TableRow>
<TextView
style="#style/Cell"
android:text="Arg 1"
android:textStyle="bold" />
<ImageButton
style="#style/Cell"
android:src="#mipmap/ic_launcher" />
<ImageButton
style="#style/Cell"
android:src="#mipmap/ic_launcher" />
<ImageButton
style="#style/Cell"
android:src="#mipmap/ic_launcher" />
</TableRow>
<!--Next Rows...-->
</TableLayout>
<!--//..-->
</RelativeLayout>
How can I make this? It looks nice and I'd like to use something like this.
The lines at the top should correspond to the end of the title
Actually, these types of view are mostly done with custom views.
This tutorial is useful for custom views.
But you can cheat a little bit, create backgound.xml inside the drawable folder, and paste the code:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:color="#color/blue" android:width="4dp"/>
<corners android:radius="10dp"/>
<solid android:color="#color/white"/>
</shape>
then create custom_background.xml for your layout, and paste the following code
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="300dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<LinearLayout
android:background="#drawable/background"
android:layout_marginTop="15dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:textSize="20sp"
android:textAlignment="center"
android:textColor="#color/blue"
android:layout_gravity="center"
android:text="Something"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<TextView
android:padding="2dp"
android:textColor="#color/blue"
android:textSize="25sp"
android:background="#color/white"
android:layout_marginStart="50dp"
android:text="Title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
Then you will get the following picture
Note
I am using androidX
Instead of LinearLayout you can place any layout
1) Migrate your project to androidx.
2) Include dependency in your build.gradle:
implementation 'com.google.android.material:material:1.0.0'
3) Use in your layout:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_height="wrap_content"
android:hint="#string/hint_text">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
4) Don't forget to change your Base Application Theme AppTheme to Material Component theme.
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
You need to use material component theme!!
I have the following layout XML:
<android.support.v7.widget.AppCompatSpinner
android:id="#+id/content_spinner"
style="#style/Widget.AppCompat.Spinner.Underlined"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#drawable/border"
android:entries="#array/books"
android:spinnerMode="dropdown"
android:theme="#style/large_spinner"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
And #style/large_spinner looks like this:
<style name="large_spinner" parent="Widget.AppCompat.Light.DropDownItem.Spinner">
<item name="android:paddingStart">0dp</item>
<item name="android:paddingEnd">0dp</item>
<item name="android:textColor">#color/nearlyBlack</item>
<item name="android:textSize">30sp</item>
<item name="android:drawableRight">#drawable/ic_menu_camera</item>
</style>
Which gives me the camera icon to the right of the spinner, which is want. However when I drop down the spinner the icon is on every single item, which I dont want. I just want the icon to the right on the spinner, not in every single item.
How can i achieve this?
Try this
<android.support.v7.widget.AppCompatSpinner
android:id="#+id/content_spinner"
style="#style/Widget.AppCompat.Spinner.Underlined"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#drawable/test"
android:entries="#array/books"
android:spinnerMode="dropdown"
android:theme="#style/large_spinner"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:background="#drawable/test"
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item>
<shape>
<solid android:color="#android:color/white" />
<corners android:radius="4dp" />
<padding android:left="8dp" />
</shape>
</item>
<item android:gravity="left|bottom" android:drawable="#drawable/ic_menu_camera" />
</layer-list>
</item>
</selector>
style name="large_spinner"
<style name="large_spinner" parent="Widget.AppCompat.Light.DropDownItem.Spinner">
<item name="android:paddingStart">0dp</item>
<item name="android:paddingEnd">0dp</item>
<item name="android:textColor">#color/nearlyBlack</item>
<item name="android:textSize">30sp</item>
</style>