如何从 Tablayout 中删除 Elevation?
How to remove the Elevation from the Tablayout?
我们今天创建了一个 tablayout,但是我们有一个问题,tablayout 有高度(或顶部的线性?)
无论如何,我们如何才能删除海拔? (顺便说一句,这是我们的第一个应用程序)
活动中的代码:
private TabLayout tabLayout;
private AppBarLayout appBarLayout;
private ViewPager viewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
tabLayout = (TabLayout) findViewById(R.id.tablayout_id);
appBarLayout = (AppBarLayout) findViewById(R.id.appbar_id);
viewPager = (ViewPager) findViewById(R.id.viewpager_id);
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.AddFragment(new Tab1(), "Watching");
adapter.AddFragment(new Tab2(), "Completed");
adapter.AddFragment(new Tab3(), "Droped");
adapter.AddFragment(new Tab4(), "On hold");
adapter.AddFragment(new Tab5(), "Plan to watch");
viewPager.setAdapter(adapter);
tabLayout.setupWithViewPager(viewPager);
}
}
ViewpagerAdapter 中的代码:
public class ViewPagerAdapter extends FragmentStatePagerAdapter {
private final List<Fragment> fragmentList = new ArrayList<>();
private final List<String> FragmentListTitles = new ArrayList<>();
public ViewPagerAdapter(@NonNull FragmentManager fm, int behavior) {
super(fm, behavior);
}
public ViewPagerAdapter(FragmentManager supportFragmentManager) {
super(supportFragmentManager);
}
@NonNull
@Override
public Fragment getItem(int position) {
return fragmentList.get(position);
}
@Override
public int getCount() {
return FragmentListTitles.size();
}
@Nullable
@Override
public CharSequence getPageTitle(int position) {
return FragmentListTitles.get(position);
}
public void AddFragment(Fragment fragment, String Title) {
fragmentList.add(fragment);
FragmentListTitles.add(Title);
}
}
我是新来的,请不要杀了我:/
在您的 toolbar
中将 app:elevation
设置为 0dp
,如下所示:
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
app:elevation="0dp"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
我们今天创建了一个 tablayout,但是我们有一个问题,tablayout 有高度(或顶部的线性?)
无论如何,我们如何才能删除海拔? (顺便说一句,这是我们的第一个应用程序)
活动中的代码:
private TabLayout tabLayout;
private AppBarLayout appBarLayout;
private ViewPager viewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
tabLayout = (TabLayout) findViewById(R.id.tablayout_id);
appBarLayout = (AppBarLayout) findViewById(R.id.appbar_id);
viewPager = (ViewPager) findViewById(R.id.viewpager_id);
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.AddFragment(new Tab1(), "Watching");
adapter.AddFragment(new Tab2(), "Completed");
adapter.AddFragment(new Tab3(), "Droped");
adapter.AddFragment(new Tab4(), "On hold");
adapter.AddFragment(new Tab5(), "Plan to watch");
viewPager.setAdapter(adapter);
tabLayout.setupWithViewPager(viewPager);
}
}
ViewpagerAdapter 中的代码:
public class ViewPagerAdapter extends FragmentStatePagerAdapter {
private final List<Fragment> fragmentList = new ArrayList<>();
private final List<String> FragmentListTitles = new ArrayList<>();
public ViewPagerAdapter(@NonNull FragmentManager fm, int behavior) {
super(fm, behavior);
}
public ViewPagerAdapter(FragmentManager supportFragmentManager) {
super(supportFragmentManager);
}
@NonNull
@Override
public Fragment getItem(int position) {
return fragmentList.get(position);
}
@Override
public int getCount() {
return FragmentListTitles.size();
}
@Nullable
@Override
public CharSequence getPageTitle(int position) {
return FragmentListTitles.get(position);
}
public void AddFragment(Fragment fragment, String Title) {
fragmentList.add(fragment);
FragmentListTitles.add(Title);
}
}
我是新来的,请不要杀了我:/
在您的 toolbar
中将 app:elevation
设置为 0dp
,如下所示:
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
app:elevation="0dp"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />