Skip to main content

Posts

Showing posts from December, 2014

use view pager and sliding tabs

make fragments and corressponding layout make viewpager adapter import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; public class MyPagerAdapter extends FragmentPagerAdapter {     public MyPagerAdapter(FragmentManager fm) {         super(fm);     }     @Override     public Fragment getItem(int position) {         Fragment f = null;         if (position == 0) {             f = new FragmentA();         }         if (position == 1) {             f = new FragmentB();         }         if (posi...

Use toolbar in android

Set the theme as Theme.AppCompat.Light.NoActionBar (it will make toggle and title color as black, to keep them white use Theme.AppCompat.NoActionBar) Make a separate app_bar.xml with the code <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.Toolbar     xmlns:android=" http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="wrap_content"> </android.support.v7.widget.Toolbar> include this layout at the top in your main activity layout using this code <include        android:id="@+id/app_bar"        layout="@layout/app_bar">    </include> add reference of this toolbar in mainactivity java file Toolbar tb=(Toolbar)findViewById(R.id.app_bar); setSupportActionBar(tb); getSupportActionBar().setHomeButtonEnabled(true);   //to make enable back buttton and ...

Overriding fonts

make a java file with this code import java.lang.reflect.Field; import android.content.Context; import android.graphics.Typeface; public final class FontsOverride {     public static void setDefaultFont(Context context,             String staticTypefaceFieldName, String fontAssetName) {         final Typeface regular = Typeface.createFromAsset(context.getAssets(),                 fontAssetName);         replaceFont(staticTypefaceFieldName, regular);     }     protected static void replaceFont(String staticTypefaceFieldName,             final Typeface newTypeface) {         try {             final F...

Create custom listview

Prepare data sources [Images+Titles+Description] to displayed in each row Define single row appearance in layout with ids for every element you want to appear different. Create Custom Adpater extend a class to ArrayAdapter, define a constructor, override getView() method Add Listview to the layout , and add reference of it in the respective java class. In the custom list adapter add constructor with passing every element of the row Context context;     int[] images;     String[] titles;     String[] location;     String[] dates;     String[] times;     public MainListAdapter(Context context, String[] titles,int[] images,String[] location,String[] dates,String[] times) {         super(context, R.layout.singlerowmain,R.id.listTitle,titles);         this.context=context;         this.imag...

Color resources for android

Essential and beautiful color pallete for android applications. Just copy and paste the below code in styles.xml     <color name="black">#333</color>     <color name="white">#ffffffff</color>     <color name="blue">#4184F3</color>     <color name="red">#D40000</color>     <color name="orange">#F3501D</color>     <color name="yellow">#F5BE25</color>     <color name="darkgreen">#0A7F42</color>     <color name="seagreen">#33B779</color>     <color name="lightblue">#029AE4</color>     <color name="deepblue">#3F5CA9</color>     <color name="lavender">#7885CA</color>     <color name="deeppurple">#8D23A9</color>     <color name="fadered">#E57B72</color...