Skip to content

Commit

Permalink
edit Tablayout
Browse files Browse the repository at this point in the history
  • Loading branch information
asgharzadeh committed Jul 1, 2019
1 parent ce8c221 commit 3e0143a
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@
@SuppressLint("ValidFragment")
public class PersianDateRangePicker extends DialogFragment implements View.OnClickListener {

private TabLayout tabLayout;
//private TabLayout tabLayout;
private ViewPager viewPager;
private TabAdapterDateRangePicker adapter;
private View Cansel, Ok;
private TextView DoneTxt, CanselTxt;
private String DoneText, CanselText;
private ShamsiDate shamsiDate = new ShamsiDate();
private ImageView DoneImg, CanselImg;
private TextView dateFromTv , dateToTv;

private int backgroundColor = -1;
private int ButtonTextColor = -1;
Expand Down Expand Up @@ -84,10 +85,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
if (typeface != null) {
DoneTxt.setTypeface(typeface);
CanselTxt.setTypeface(typeface);
dateToTv.setTypeface(typeface);
dateFromTv.setTypeface(typeface);
}

if (TabIndicatorColor != -1) {
tabLayout.setSelectedTabIndicatorColor(TabIndicatorColor);
//tabLayout.setSelectedTabIndicatorColor(TabIndicatorColor);
}

if (DoneText != null) {
Expand Down Expand Up @@ -120,7 +123,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa

private void init() {
viewPager = view.findViewById(R.id.viewPager);
tabLayout = view.findViewById(R.id.tab_layout);
//tabLayout = view.findViewById(R.id.tab_layout);
dateFromTv = view.findViewById(R.id.textView);
dateToTv = view.findViewById(R.id.textView2);
DoneImg = view.findViewById(R.id.img_tick);
CanselImg = view.findViewById(R.id.img_mult);
Cansel = view.findViewById(R.id.cansel);
Expand All @@ -131,6 +136,8 @@ private void init() {
Cansel.setOnClickListener(this);
Ok = view.findViewById(R.id.ok);
Ok.setOnClickListener(this);
dateFromTv.setOnClickListener(this);
dateToTv.setOnClickListener(this);
}

@Override
Expand All @@ -157,7 +164,7 @@ public void onResume() {
} else {
bgShape2.setColor(getActivity().getResources().getColor(R.color.white));
}
tabLayout.setBackground(bgShape2);
//tabLayout.setBackground(bgShape2);

}

Expand All @@ -168,6 +175,14 @@ public void onClick(View v) {
canselButton();
} else if (i == R.id.ok) {
okButton();
} else if (i == R.id.textView2) {
dateFromTv.setTextColor(getResources().getColor(R.color.white_smoke));
dateToTv.setTextColor(getResources().getColor(R.color.white));
viewPager.setCurrentItem(0);
} else if (i == R.id.textView) {
dateFromTv.setTextColor(getResources().getColor(R.color.white));
dateToTv.setTextColor(getResources().getColor(R.color.white_smoke));
viewPager.setCurrentItem(1);
}
}

Expand All @@ -183,48 +198,71 @@ private void okButton() {
}

private void setupTab() {
adapter = new TabAdapterDateRangePicker(getChildFragmentManager(), tabLayout.getTabCount());
adapter = new TabAdapterDateRangePicker(getChildFragmentManager(), 2);
viewPager.setAdapter(adapter);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
//viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
viewPager.setCurrentItem(SetCurrentItem);
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
switch (tab.getPosition()) {
case 0:
viewPager.setCurrentItem(0);
break;
case 1:
viewPager.setCurrentItem(1);
break;
}
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

}

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

public void onPageSelected(int position) {
if (position == 0) {
dateFromTv.setTextColor(getResources().getColor(R.color.white_smoke));
dateToTv.setTextColor(getResources().getColor(R.color.white));
viewPager.setCurrentItem(0);
} else if (position == 1) {
dateFromTv.setTextColor(getResources().getColor(R.color.white));
dateToTv.setTextColor(getResources().getColor(R.color.white_smoke));
viewPager.setCurrentItem(1);
}
}

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

}
});
tabLayout.setupWithViewPager(viewPager);

if (typeface != null) {
for (int i = 0; i < tabLayout.getTabCount(); i++) {
//noinspection ConstantConditions
TextView tv = (TextView) LayoutInflater.from(getActivity()).inflate(R.layout.custom_tab_item, null);
tv.setTypeface(typeface);

if (TabTextColor != -1 && TabSelectedTextColor != -1) {
tv.setTextColor(TabTextColor);
}

tabLayout.getTabAt(i).setCustomView(tv);
}
}
// tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
// @Override
// public void onTabSelected(TabLayout.Tab tab) {
// switch (tab.getPosition()) {
// case 0:
// viewPager.setCurrentItem(0);
// break;
// case 1:
// viewPager.setCurrentItem(1);
// break;
// }
// }
//
// @Override
// public void onTabUnselected(TabLayout.Tab tab) {
//
// }
//
// @Override
// public void onTabReselected(TabLayout.Tab tab) {
//
// }
// });

// if (typeface != null) {
// for (int i = 0; i < tabLayout.getTabCount(); i++) {
// //noinspection ConstantConditions
// TextView tv = (TextView) LayoutInflater.from(getActivity()).inflate(R.layout.custom_tab_item, null);
// tv.setTypeface(typeface);
//
// if (TabTextColor != -1 && TabSelectedTextColor != -1) {
// tv.setTextColor(TabTextColor);
// }
//
// tabLayout.getTabAt(i).setCustomView(tv);
// }
// }

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="wrap_content">
Expand All @@ -11,28 +12,78 @@
android:id="@+id/root2"
android:orientation="vertical">

<android.support.design.widget.TabLayout
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:id="@+id/tab_layout"
android:background="@color/green"
app:tabTextColor="@color/white"
app:tabIndicatorColor="@color/white"
app:tabSelectedTextColor="@color/white">

<android.support.design.widget.TabItem
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="تا تاریخ"
android:id="@+id/number1"/>
android:layout_height="?android:actionBarSize"
android:background="@color/green">

<android.support.design.widget.TabItem
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="از تاریخ"
android:id="@+id/number2"/>

</android.support.design.widget.TabLayout>
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5" />

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:textColor="@color/white"
android:textStyle="bold"
android:text="از تاریخ"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/guideline"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:text="تا تاریخ"
android:textColor="@color/white"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/guideline"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

<!--<android.support.design.widget.TabLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="?android:attr/actionBarSize"-->
<!--android:id="@+id/tab_layout"-->
<!--android:background="@color/green"-->
<!--app:tabTextColor="@color/white"-->
<!--app:tabIndicatorColor="@color/white"-->
<!--app:tabSelectedTextColor="@color/white">-->

<!--&lt;!&ndash;<android.support.design.widget.TabItem&ndash;&gt;-->
<!--&lt;!&ndash;android:layout_width="match_parent"&ndash;&gt;-->
<!--&lt;!&ndash;android:layout_height="match_parent"&ndash;&gt;-->
<!--&lt;!&ndash;android:text="تا تاریخ"&ndash;&gt;-->
<!--&lt;!&ndash;android:id="@+id/number1"/>&ndash;&gt;-->

<!--&lt;!&ndash;<android.support.design.widget.TabItem&ndash;&gt;-->
<!--&lt;!&ndash;android:layout_width="match_parent"&ndash;&gt;-->
<!--&lt;!&ndash;android:layout_height="match_parent"&ndash;&gt;-->
<!--&lt;!&ndash;android:text="از تاریخ"&ndash;&gt;-->
<!--&lt;!&ndash;android:id="@+id/number2"/>&ndash;&gt;-->

<!--</android.support.design.widget.TabLayout>-->

<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
Expand Down

0 comments on commit 3e0143a

Please sign in to comment.