Thursday 30 August 2018

How To Store User ID using SharedPreferences

Step 1:

Set Method 

int user_id=bean.getId();

store(user_id);


private void store(int userID){
    SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit();
    editor.putInt("User_id", userID);
    editor.commit();
}



Get Method 

private int getUserID(){
    SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
    int user_id = prefs.getInt("User_id", 0);
    return user_id;
}

int id=getUserID();
if(id == 0){
    Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
    startActivity(intent);
    finish();
}else{
    Intent i=new Intent(SplashActivity.this,MainActivity.class);
    startActivity(i);
    finish();
}


Tuesday 28 August 2018

How to Set NavigationView Item Color

<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
    <item
        android:id="@+id/navigation_item_1"
        android:icon="@drawable/ic_1"
        android:title="@string/navigation_item_1"/>

    <item
        android:id="@+id/navigation_item_2"
        android:icon="@drawable/ic_2"
        android:title="@string/navigation_item_2"/>
</group>
res/drawable.nav_item_drawable.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@drawable/highlight_color" android:state_checked="true"/>
</selector>
res/drawable/highlight_color.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="rectangle">
 <solid android:color="YOUR HIGHLIGHT COLOR"/>
</shape>
<android.support.design.widget.NavigationView
android:id="@+id/activity_main_navigationview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/drawer_header"
app:itemIconTint="@color/black"
app:itemTextColor="@color/primary_text"
app:itemBackground="@drawable/nav_item_drawable"
app:menu="@menu/menu_drawer">
<style name="ThemeOverlay.AppCompat.navTheme">
        <!-- Color of text and icon when SELECTED -->
        <item name="colorPrimary">@color/color_of_your_choice</item> 

        <!-- Background color when SELECTED -->
        <item name="colorControlHighlight">@color/color_of_your_choice</item> 

    </style>
<android.support.design.widget.NavigationView
android:id="@+id/activity_main_navigationview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:theme="@style/ThemeOverlay.AppCompat.navTheme"
app:headerLayout="@layout/drawer_header"
app:menu="@menu/menu_drawer">


Monday 27 August 2018

How To Create TapView

                                       


Step 1:

activity_taps.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_height="match_parent">
 
    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorLiteGreen">
    </android.support.design.widget.TabLayout>
    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

Step 2:

TapViewActivity.java
public class TapViewActivity  extends AppCompatActivity {
    TabLayout tabLayout;
    ViewPager viewPager;
    ImageView im_arrow;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_taps);

        tabLayout=(TabLayout)findViewById(R.id.tabLayout);
        viewPager=(ViewPager)findViewById(R.id.viewPager);
        im_arrow=(ImageView)findViewById(R.id.im_arrow);

        tabLayout.addTab(tabLayout.newTab().setText("Tap1"));
        tabLayout.addTab(tabLayout.newTab().setText("Tap2"));
        tabLayout.addTab(tabLayout.newTab().setText("Tap3"));
        tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);


        im_arrow.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View v) {
                finish();
            }
        });

        final ViewPagerAdapter adapter = new ViewPagerAdapter(this,getSupportFragmentManager(), tabLayout.getTabCount());
        viewPager.setAdapter(adapter);

        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));

        tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override 
           public void onTabSelected(TabLayout.Tab tab) {
                viewPager.setCurrentItem(tab.getPosition());
            }
            @Override 
           public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override  
          public void onTabReselected(TabLayout.Tab tab) {

            }
        });

    }
}

Step 3:

Tap1.java

public class Tap1 extends Fragment {

    LinearLayout ly1,ly2;
    public ApprovedTap() {
        // Required empty public constructor    }

    @Override    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final View view = inflater.inflate(R.layout.tap1, container, false);
        // Inflate the layout for this fragment   
     return view;

    }}

Step 4:

Tap2.java

public class Tap2 extends Fragment {

    LinearLayout ly1,ly2;
    public ApprovedTap() {
        // Required empty public constructor    }

    @Override    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final View view = inflater.inflate(R.layout.tap2, container, false);

        // Inflate the layout for this fragment 
       return view;

    }}

Step 5:

Tap3.java

public class Tap3 extends Fragment {

    LinearLayout ly1,ly2;
    public ApprovedTap() {
        // Required empty public constructor    }

    @Override    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final View view = inflater.inflate(R.layout.tap3, container, false);

        // Inflate the layout for this fragment  
     return view;

    }}

Step 6:

tap1.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
 android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="2"
        android:gravity="center|left">
        <TextView 
           android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Tap 1"
            android:layout_marginLeft="20dp"
            android:textColor="@color/colorDarkGreen"
            android:textSize="20dp"/>
    </LinearLayout>
</LinearLayout>

Step 7:

tap2.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
 android:layout_width="match_parent"
android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="2"
        android:gravity="center|left">
        <TextView     
       android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Tap 2"
            android:layout_marginLeft="20dp"
            android:textColor="@color/colorDarkGreen"
            android:textSize="20dp"/>
    </LinearLayout>
</LinearLayout>

Step 8:

tap3.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
 android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="2"
        android:gravity="center|left">
        <TextView 
           android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Tap 3"
            android:layout_marginLeft="20dp"
            android:textColor="@color/colorDarkGreen"
            android:textSize="20dp"/>
    </LinearLayout>
</LinearLayout>



HOW TO CREATE CIRCLE IMAGE VIEW

Step 1: implementation 'de.hdodenhof:circleimageview:3.0.0' Step 2: <de.hdodenhof.circleimageview.CircleImageView xmlns:ap...