Posts

Android Toast

Image
With code // create instance Toast toast = Toast . makeText ( context , text , duration ); // set message color TextView textView = ( TextView ) toast . getView (). findViewById ( android . R . id . message ); textView . setTextColor ( Color . YELLOW ); // set background color toast . getView (). setBackgroundColor ( getResources (). getColor ( R . color . indigo )); With custom view I. Declare your custom view inside of any  layout.xml  file. <? xml version = "1.0" encoding = "utf-8" ?> <TextView xmlns:android = "http://schemas.android.com/apk/res/android" android:id = "@+id/txtMessage" android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:drawableStart = "@drawable/ic_report_problem" android:drawablePadding = "8dp" android:paddingTop = "8dp" android:p...

Android Toast

Image
From google material design  documentation . Android also provides a toast, primarily used for system messaging. Toasts are similar to snackbars but do not contain actions and cannot be swiped off screen. How to add? Create Toast instance with make() method. Then call show() method. Toast.makeText(context, "No network connection.", duration).show(); To specify how long Toast will be visible on screen use duration parameter of makeText() method or setDuration method. // you can use only those 2 predefined constants duration = Toast.LENGTH_SHORT; // 2000 millis duration = Toast.LENGTH_LONG; // 3500 millis toast.setDuration(duration); To hide Toast manually at any time use cancel() method. Toast toast= Toast.make(view, text, duration).show(); toast.cancel(); //hide toast Close the view if it's showing, or don't show it if it isn't showing yet. You do not normally have to call this. Normally view will disappear on its own after the appro...

ANDROID TAB

Image
From google material design  documentation Tabs make it easy to explore and switch between different views or functional aspects of an app or to browse categorized data sets. HOW TO ADD? I. In your build.gradle add latest design and appcompat libraries. dependencies { compile 'com.android.support:appcompat-v7:X.X.X' compile 'com.android.support:design:X.X.X' compile 'com.android.support:support-v13:X.X.X' // where X.X.X version // if you want to support android sdk < 13 // you need to add support library v4 instead of v13 } II. Make your activity extend  android.support.v7.app.AppCompatActivity . public class MainActivity extends AppCompatActivity { ... } III. Declare TabLayout and ViewPager in your  layout.xml  file. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" an...

SEARCH FILTER

Image
rom Google Material Design  documentation . The app bar can act as a text input field. As the user types, the content underneath is filtered and sorted. HOW TO ADD? I. In your build.gradle add latest appcompat library. dependencies { compile 'com.android.support:appcompat-v7:X.X.X' // where X.X.X version } II. Create a searchable configuration in a  searchable.xml  saved in res/xmldirectory. <?xml version="1.0" encoding="utf-8"?> <searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="@string/app_label" android:hint="@string/search_hint" > </searchable> III. Declare your searchable activity in the  AndroidManifest.xml  file. <activity android:name=".SearchActivity"> <intent-filter> <action android:name="android.intent.action.SEARCH" /> </intent-filter> <meta-data android:name=...

ANDROID MATERIAL DESIGN RATING BAR

Image
A RatingBar is an extension of SeekBar and ProgressBar that shows a rating in stars. The user can touch/drag or use arrow keys to set the rating when using the default size RatingBar. The smaller RatingBar style ( ratingBarStyleSmall ) and the larger indicator-only style ( ratingBarStyleIndicator ) do not support user interaction and should only be used as indicators. How to add? I. In your build.gradle add latest appcompat library. dependencies { compile 'com.android.support:appcompat-v7:X.X.X' // where X.X.X version } II. Make your activity extend  android.support.v7.app.AppCompatActivity . public class MainActivity extends AppCompatActivity { ... } III. Declare your RatingBar inside any  layout.xml  file. <RatingBar android:rating="3.5" android:stepSize="0.5" android:numStars="5" android:layout_width="wrap_content" android:layout_height="wrap_content"/> I. Declare cu...

TEXT FIELD

Image
From google material design  documentation . Text fields allow the user to input text, select text (cut, copy, paste), and lookup data via auto-completion. HOW TO ADD? I. In your build.gradle add latest appcompat library. dependencies { compile 'com.android.support:appcompat-v7:X.X.X' // where X.X.X version } II. Make your activity extend  android.support.v7.app.AppCompatActivity . public class MainActivity extends AppCompatActivity { ... } III. Declare your EditText inside any  layout.xml  file. <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Hint text"/> I. Declare custom style in your  styles.xml  file. <style name="MyEditText" parent="Theme.AppCompat.Light"> <item name="colorControlNormal">@color/indigo</item> <item name="colorControlActivated">@color/pink</item> </...