#Sketchware
code 1 tab layout with view pager
viewPager = new androidx.viewpager.widget.ViewPager(this);
viewPager.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
MyPagerAdapter adapter = new MyPagerAdapter();
viewPager.setAdapter(adapter);
viewPager.setCurrentItem(0);
base.addView(viewPager);
tabLayout = new com.google.android.material.tabs.TabLayout(this);
tabLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
tabLayout.setTabGravity(tabLayout.GRAVITY_FILL);
tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#3F51B5"));
tabLayout.setTabTextColors(Color.parseColor("#B71C1C"), Color.parseColor("#B71C1C"));
//tabLayout.setTabMode(tabLayout.MODE_SCROLLABLE);
//tabLayout.setTabMode(tabLayout.MODE_FIXED);
tabLayout.setupWithViewPager(viewPager);
cod.addView(tabLayout);
}
private class MyPagerAdapter extends androidx.viewpager.widget.PagerAdapter {
public int getCount() {
return 3;
}
@Override public Object instantiateItem(ViewGroup collection, int position) {
LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.empty, null);
LinearLayout container = (LinearLayout) v.findViewById(R.id.linear1);
if (position == 0) {
ViewGroup parent = (ViewGroup) layout1.getParent();
if (parent != null) {
parent.removeView(layout1);
}
container.addView(layout1);
}
else if (position == 1) {
ViewGroup parent = (ViewGroup) layout2.getParent();
if (parent != null) {
parent.removeView(layout2);
}
container.addView(layout2);
}
else if (position == 2) {
ViewGroup parent = (ViewGroup) layout3.getParent();
if (parent != null) {
parent.removeView(layout3);
}
container.addView(layout3);
}
collection.addView(v, 0);
return v;
}
@Override public void destroyItem(ViewGroup collection, int position, Object view) {
collection.removeView((View) view);
trash.addView((View) view);
}
@Override public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "الرئيسيه";
case 1:
return "Tab 2";
case 2:
return "Tab 3";
default:
return null;
}
}
@Override public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == ((View) arg1);
}
@Override public Parcelable saveState() {
return null;
}
}
androidx.viewpager.widget.ViewPager viewPager;
com.google.android.material.tabs.TabLayout tabLayout;
private void foo() {
code (navigation bar 1)
com.google.android.material.bottomnavigation.BottomNavigationView btm= new com.google.android.material.bottomnavigation.BottomNavigationView(MainActivity.this);
btm.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
navigation_linear.addView(btm);
navigation_linear.setElevation(16);
Menu menu = btm.getMenu();
final int A = 0;
final int B = 1;
final int C = 2;
final int D = 3;
menu.add(Menu.NONE, A, Menu.NONE, "البروفايل").setIcon(R.drawable.icona);
menu.add(Menu.NONE, B, Menu.NONE, "حماية").setIcon(R.drawable.iconb);
menu.add(Menu.NONE, C, Menu.NONE, "اعدادات").setIcon(R.drawable.iconc);
menu.add(Menu.NONE,D, Menu.NONE, "منزل").setIcon(R.drawable.icond);
code 3 (navigation. bar 2)
btm.setOnNavigationItemSelectedListener(new com.google.android.material.bottomnavigation.BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(final MenuItem item) {
switch (item.getItemId()){
case A:
_callHome();
return true;
case B:
_callProfile();
return true;
case C:
_callsetting();
return true;
case D:
_callstor();
return true;
default:
return true;
}
} });
link project
[ Ссылка ]
Ещё видео!