Showing posts with label style. Show all posts
Showing posts with label style. Show all posts

Wednesday, September 23, 2015

Example of using "?android:attr/selectableItemBackground" and "?android:attr/selectableItemBackgroundBorderless"


Example to apply "?android:attr/selectableItemBackground" and "?android:attr/selectableItemBackgroundBorderless" to android:background, in XML file.
  • ?android:attr/selectableItemBackground for a bounded ripple.
  • ?android:attr/selectableItemBackgroundBorderless for a ripple that extends beyond the view. It will be drawn upon, and bounded by, the nearest parent of the view with a non-null background. (introduced in API level 21)
reference: http://developer.android.com/training/material/animations.html#Touch


<LinearLayout
    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"
    android:padding="30dp"
    android:orientation="vertical"
    tools:context=".MainActivity">
    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:autoLink="web"
        android:text="http://android-er.blogspot.com/"
        android:textStyle="bold" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="30dp"
        android:orientation="vertical">
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Normal Button"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="\?android:attr/selectableItemBackground"
            android:textAllCaps="false"
            android:background="?android:attr/selectableItemBackground" />
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="\?android:attr/selectableItemBackgroundBorderless"
            android:textAllCaps="false"
            android:background="?android:attr/selectableItemBackgroundBorderless" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="30dp"
        android:orientation="vertical"
        android:background="#80C0C0">
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Normal Button"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="\?android:attr/selectableItemBackground"
            android:textAllCaps="false"
            android:background="?android:attr/selectableItemBackground" />
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="\?android:attr/selectableItemBackgroundBorderless"
            android:textAllCaps="false"
            android:background="?android:attr/selectableItemBackgroundBorderless" />
    </LinearLayout>
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:src="@mipmap/ic_launcher"
        android:clickable="true"
        android:background="?android:attr/selectableItemBackgroundBorderless" />
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:src="@mipmap/ic_launcher"
        android:clickable="true"
        android:background="?android:attr/selectableItemBackgroundBorderless" />
</LinearLayout>


Saturday, September 19, 2015

Customize color for your app, for Material Theme, using Android Studio


The new material theme provides:

  • System widgets that let you set their color palette
  • Touch feedback animations for the system widgets
  • Activity transition animations

You can customize the look of the material theme according to your brand identity with a color palette you control. You can tint the action bar and the status bar using theme attributes, as shown in Here.


reference: https://developer.android.com/training/material/theme.html

This video show how to do it in Android Studio.


Create values/colors.xml to define our custom color.
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="primary">#FFFF00</color>
    <color name="primary_dark">#502020</color>
    <color name="text_primary">#FF00ff00</color>
    <color name="text_secondary">#FFff0000</color>
    <color name="window_background">#000000</color>
    <color name="nav_color">#505050</color>
</resources>


Edit values-v21/styles.xml to use our custom color.
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme" parent="android:Theme.Material.Light">
        <item name="android:colorPrimary">@color/primary</item>
        <item name="android:colorPrimaryDark">@color/primary_dark</item>
        <item name="android:textColorPrimary">@color/text_primary</item>
        <item name="android:textColor">@color/text_secondary</item>
        <item name="android:windowBackground">@color/window_background</item>
        <item name="android:navigationBarColor">@color/nav_color</item>
    </style>
</resources>


reference: Customize the Color Palette