customize the height of tab indicator in view pager? - android

I am looking to style the tab indicator like pininterest where the indicator does not look like the normal "android" style . Is there some attribute where i can set the indicator height ?Please look into the following image .

It might be not a proper solution, and question is really old, but as I haven't found any proper solutions, this is how I did it:
I created a layerList file called indicator:
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#FF0000" />
</shape>
</item>
<item android:bottom="3dp">
<shape android:shape="rectangle">
<solid android:color="#efefef" />
</shape>
</item>
</layer-list>
And just set it as my tab indicator background:
<style name="CustomTabPageIndicator" parent="#android:style/Widget.Holo.ActionBar.TabView">
<item name="android:background">#drawable/indicator</item>
</style>
I've also applied this theme to my actionBar:
<style name="MyActionBarTheme" parent="android:style/Widget.Holo.ActionBar">
<item name="android:actionBarTabStyle">#style/CustomTabPageIndicator</item>
</item> </style>
It works because in indicator.xml first shape is lower shape, which is actual indicator, and to I set its height by providing bottom padding for another shape which color is identical to actionbar color.

just set layout_height attribute in your layout file:
com.viewpagerindicator.TitlePageIndicator
android:layout_height="#dimen/indicator_height"

Using the material design TabLayout, You can set the height with app:tabIndicatorHeight
<com.google.android.material.tabs.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorHeight="4dp" />

Related

How to make buttons rounded with Material Design Theming?

I want my button to have rounded corners like:
// Image taken from google
To achieve this with material theming in android is to set the: shapeAppearanceSmallComponent to have a rounded corner.
But setting shapeAppearanceSmallComponent also affects all other components such as EditText so now they are rounded as well.
So instead of setting it to shapeAppearanceSmallComponent, I created a shapeMaterialOverlay. Set this overlay to a buttonStyle and set this button style in the theme as the default button style.
It works but only for default buttons. If I needed a TextButton as such:
<Button
...
style="#style/Widget.MaterialComponents.Button.TextButton"/>
The TextButton won't be rouned. So as a workaround, I created MyTextButton style which extends from TextButton and set the shapeOverlay there as well.
so Now if I need a TextButton, I'll do:
<Button
...
style="#style/Widget.MaterialComponents.Button.MyTextButton"/>
instead.
I will have to do this for all other button types. I was wondering whether this approach is correct and if not, can anyone guide me on how to properly do this?
Thank you very much.
Just use the app:shapeAppearanceOverlay attribute in the layout.
<com.google.android.material.button.MaterialButton
app:shapeAppearanceOverlay="#style/buttomShape"
.../>
with:
<style name="buttomShape">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">50%</item>
</style>
The only way to apply it to all buttons is to define custom styles for all the button styles as you are just doing. Something like:
<style name="...." parent="Widget.MaterialComponents.Button">
<item name="shapeAppearance">#style/buttomShape</item>
</style>
<style name="..." parent="Widget.MaterialComponents.Button.TextButton">
<item name="shapeAppearance">#style/buttomShape</item>
</style>
You can set a background drawable on your button. The drawable could look like this:
<shape android:shape="rectangle">
<solid android:color="#android:color/blue" />
<corners android:radius="10dp" />
</shape>
This will give you rounded corners for your button background.
You know there is a site for creating custom layouts for buttons
here is the Link
it is a auto generated Code you don't have to code. Maybe it will be helpful for everyone
Create a drawable xml file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<stroke
android:color="#color/colorPrimary"
android:width="1dp" />
<corners
android:radius="30dp"
android:bottomLeftRadius="30dp"
/>
<solid
android:color="#4c95ec"
/>
</shape>

Changing tab indicator background (for all the tablayout view)

I have a question which I can't find an answer to and really have to solve.
I am trying to change the background for the tab layout indicator but JUST FOR IT, i.e. if the entire tablayout is green and the tablayoutindicator height is 4dp I want the ENTIRE bottom 4dp of the tablayoutview will be in another color (lets say red) is that possible?
Before you answer please note I'm not talking about app:tabIndicatorColor property but on the entire height of the tabIndicator (regardless of the tabIndicator itself).
For example, on the attached image the app:tabIndicatorColor is white but the background of it is black while the entire view is a gardient of blue.
Edit -
I managed to do it using a FrameLayout having the bottom view in black while the tablayout is above it with its properties, I'm still looking for a more "clean" way to achieve the same thing
To achieve what you are looking for you can try the following
Create a selector tab_layout_selector
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="false" android:state_pressed="false">
<layer-list>
<!-- Stripe bottom indicator color -->
<item android:top="-5dp" android:left="-5dp" android:right="-5dp">
<shape android:shape="rectangle">
<stroke android:color="#color/red" android:width="4dp"/>
</shape>
</item>
</layer-list>
</item>
</selector>
Finally, in your TabLayout add
<android.support.design.widget.TabLayout
<!-- Whole tab background -->
android:background="#color/white"
<!-- Line color -->
android:tabBackground="#drawable/tab_layout_selector"
.... Others....
/>

Background for a specific layout in style

I have about 8 themes in my app, I need to have a specific drawable background (XML shape) for the login page only, and that can be changed when I change the theme.
Here is my default theme:
<style name="DefaultTheme" parent="CommonDark">
<item name="colorPrimary">#color/whiteTrasparentTheme</item>
<item name="colorPrimaryDark">#color/whiteTrasparentTheme</item>
<item name="colorAccent">#color/whiteTrasparentTheme</item>
<item name="buttonStyle">#style/BlackButtonText</item>
<item name="timerColor">#color/yellowTheme</item>
<item name="timerTextColor">#color/black</item>
<item name="iconTinting">#color/yellowThemeIcon</item>
<item name="iconBG">#color/yellowThemeSecondary</item>
</style>
Any help is appreciated.
Screenshots
This is what I want:
https://imgur.com/a/Y3nf2
This is what I have on all my themes
https://imgur.com/a/wD5Gd
for that you have to create a my_background_login.xml in drawable package :
in this xml you have to put this code :
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="90"
android:centerColor="#555994"
android:endColor="#b5b6d2"
android:startColor="#555994"
android:type="linear" />
<corners
android:radius="0dp"/>
</shape>
you have specify your start color , center color and end color in xml..
then set this drawable as background in your main parent layout, so whenever you want to change you can directly change from this xml.
this is the proper way to get it done..
try it

Change Line Color of EditText - Android

Can I change the line color on EditText. When is active it has some greenish color.
Is it possible to change only the color of line when is active, and how can I do this...?
You need to set background source for an edit text.
Generate it http://android-holo-colors.com/
Than you can apply generated drawable as background like android:background="#drawable/my_theme_edit_text" for the custom EditText. Or you can set that background in your app theme - you will find example in .zip file from that site
add to your themes.xml this line:
<item name="colorAccent">#color/black</item>
this sets the default color for colorControlActivated which is used to tint widgets
Here you are:
editText.getBackground().setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_ATOP);
You can set background of edittext to a rectangle with minus padding on left, right and top to achieve this.
Here is the xml example for setting different line colors for focused and not focused edittext, just set it as background of edittext.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:top="-2dp"
android:left="-2dp"
android:right="-2dp"
android:bottom="2dp">
<selector >
<item android:state_enabled="true"
android:state_focused="true">
<shape
android:shape="rectangle">
<stroke
android:width="2dp"
android:color="#6A9A3A"/>
</shape>
</item>
<item android:state_enabled="true">
<shape
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="#000000"/>
</shape>
</item>
</selector>
</item>
</layer-list>
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:background="#drawable/text"
android:ems="10"
android:textColorHint="#fefefe"
android:hint="#string/text1"
android:textColor="#fefefe"
android:inputType="textEmailAddress"
android:layout_marginTop="10dp"
/>
Use the below code in your res/drawable/text.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="24.0dp">
<shape >
<solid android:color="#fefefe" />
</shape>
</item>
</layer-list>
you can set android:backgroundTint="#color/blue" to change the color of the Edittext bottom line
I had the same problem
solved it by changing the color of the backgroundTint as follows -
android:backgroundTint="#color/light_color"
You can use the android:background = "#color/black" for the api 21 or above 21 (This will apply for lollypop device or above versions) and for below versions you should use the style to the edittext.
If your using TextInputLayouts for EditText, we should change the following properties.
<item name="colorControlNormal">#c5c5c5</item>
<item name="colorControlActivated">#color/your color</item>
<item name="colorControlHighlight">#color/your color</item>
By default colour is colorAccent.

How to make Android style windowBackground accommodate action bar

I'm trying to have a style with a background image in the top right of the screen. I have this working with
my_theme_background.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#color/myThemeBackgroundColor" />
</shape>
</item>
<item android:top="70dp">
<bitmap android:src="#drawable/bg_my_theme"
android:gravity="top|right" />
</item>
</layer-list>
Style
<style name="MyTheme" parent="AppBaseTheme">
<item name="android:windowBackground">#drawable/my_theme_background</item>
</style>
I have to use that android:top="70dp" to keep the image under the action bar. But the action bar changes height on rotation. How do I keep the image under the action bar in the xml without explicitly setting a top value?
I believe you can retreive its height via the attribute android.R.attr.actionBarSize. For instance for Honeycomb and later:
android:top="?android:attr/actionBarSize"
Or, according to Jake Wharton, for ActionBarSherlock compatibility:
android:top="?attr/actionBarSize"

Categories

Resources