我对TabLayout有两个问题
1)我可以删除TabLayout突出显示或更改高亮颜色吗?
2)我可以为标签添加涟漪效果.每个选项卡都包含TextView我尝试添加这样的自定义背景
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item android:drawable="@drawable/btn_white_bg" />
</ripple>
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
我正在以下名为FriendListActivity的屏幕上工作:
正如您在此处看到的那样,我是3个名为CHAT,GROUPS和CONTACTS的选项卡。每个选项卡都显示一些内容。例如,Groups选项卡显示了组数。单击每个Group时,将打开Group Chat屏幕.Now In Group Chat屏幕上,我有一个工具栏。请考虑以下代码:
Toolbar toolbarGroupChat = (Toolbar) findViewById(R.id.toolbarGroupChat);
setSupportActionBar(toolbarGroupChat);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(upperCase(group_name));
//ViewPager
viewPager = (ViewPager) findViewById(R.id.viewPager);
//Initializing PagerAdapter
PagerAdapter pagerAdapter = new PagerAdapter(getSupportFragmentManager(), tabLayout.getTabCount());
viewPager.setAdapter(pagerAdapter);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.setOnTabSelectedListener(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) {
}
});
Run Code Online (Sandbox Code Playgroud)
PagerAdapter.java
public class PagerAdapter extends FragmentStatePagerAdapter {
private int noOfTabs;
public PagerAdapter(FragmentManager fm, int noOfTabs) {
super(fm);
this.noOfTabs = noOfTabs;
}
@Override
public Fragment …Run Code Online (Sandbox Code Playgroud) 切换标签时,我尝试更改tabLayout的标签中图标的颜色。我setCustomView(view)用来设置像这样的图标。
View view = inflater.inflate(R.layout.layout_icon, null);
view.findViewById(R.id.icon).setBackgroundResource(R.drawable.apple);
TabLayout tabLayout = (TabLayout) rootView.findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setCustomView(view));
Run Code Online (Sandbox Code Playgroud)
选择选项卡后,我想更改其图标的颜色,但是我不知道该怎么做。如果我只是setCustomView(view)再次在选项卡上将onTabSelected两个图标分别用不同的颜色显示在选项卡内,则原始的customView不会被删除。如何删除自定义视图?或实现此目标的方法是什么?有人可以帮忙吗?提前致谢 !!
我正在使用TabLyout,但是文本和文本下方的行之间的距离太大。

当然我已经尝试过填充,但是没有运气,有什么办法可以减少这种内部填充吗?
这是我的代码:
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="0dp"
app:tabPadding="0dp"
app:tabGravity="center"
app:tabIndicatorColor="#ddffffff"
app:tabMaxWidth="0dp"
app:tabMode="scrollable"
android:visibility="visible"
app:tabSelectedTextColor="#ffffff"
app:tabTextColor="#ffffff" />
Run Code Online (Sandbox Code Playgroud)
谢谢
我的应用程序有一个activitywith NavigationView和for导航抽屉中的不同项目UI通过更改来更改fragment.其中一个这样的片段已经TabLayout实现了.
当应用程序启动时fragment,TabLayout加载并且它工作正常,但是当我在其中的不同项目之间切换navigation drawer然后返回到具有该项目的项目时TabLayout,现在在滑动选项卡时,指示器卡在选项卡和一个选项卡上的内容之间甚至没有显示.我不清楚我可能犯了什么错误.我在用
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
Run Code Online (Sandbox Code Playgroud)
这是具有NavigationView(activity_start.xml)的活动
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_start"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_start"
app:menu="@menu/start_menu" />
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
这是app_bar_start.xml的代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.optimilia.readaloud.Start">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent" …Run Code Online (Sandbox Code Playgroud) android android-fragments android-tablayout android-navigationview
public class ActivityManageCustomer extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_manage_customer);
ViewPager viewpager = (ViewPager) findViewById(R.id.viewpager);
viewpager.setAdapter(new AdapterFragmentCustomer(getSupportFragmentManager()));
TableLayout tabLayout = (TableLayout) findViewById(R.id.tabLayout);
tabLayout.setupWithViewPager(viewpager);
}
}
Run Code Online (Sandbox Code Playgroud)
tabLayout中不存在setupWithViewPager
minSdkVersion 14
targetSdkVersion 23
我正在使用标签布局,这是我的代码
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="center"
app:tabMode="fixed"
android:minHeight="?attr/actionBarSize"
app:tabTextColor="#000"
app:tabSelectedTextColor="#fff"
app:tabIndicatorColor="@android:color/white"
android:clipToPadding="false"
/>
Run Code Online (Sandbox Code Playgroud)
像这样添加标签
//创建标签
TextView tab =(TextView)LayoutInflater.from(this).inflate(R.layout.custom_tab,null); tab.setText( "家"); tab.setCompoundDrawablesWithIntrinsicBounds(0,R.mipmap.ic_home_black_24dp,0,0); tabLayout.addTab(tabLayout.newTab()setCustomView(标签).);
TextView tab2 = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
tab2.setText("Report");
tab2.setCompoundDrawablesWithIntrinsicBounds(0, R.mipmap.ic_trending_up_black_24dp, 0, 0);
tabLayout.addTab(tabLayout.newTab().setCustomView(tab2));
TextView tab3 = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
tab3.setText("Medicine");
tab3.setCompoundDrawablesWithIntrinsicBounds(0, R.mipmap.ic_home_black_24dp, 0, 0);
tabLayout.addTab(tabLayout.newTab().setCustomView(tab3));
TextView tab4 = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
tab4.setText("More");
tab4.setCompoundDrawablesWithIntrinsicBounds(0, R.mipmap.ic_trending_up_black_24dp, 0, 0);
tabLayout.addTab(tabLayout.newTab().setCustomView(tab4));
Run Code Online (Sandbox Code Playgroud)
这是我的手机截图
https://i.stack.imgur.com/kYNs1.png
Run Code Online (Sandbox Code Playgroud)
两件事1.如何从标签布局的左右两侧移除空间?
2.如何更改活动和非活动选项卡的文本颜色和图标
大家好,
我正在研究Android Material Design。
当我将模式选项卡添加到适配器中时,文本会失真,分成两个位置,如图所示。我的代码:
private void setupViewPager(ViewPager viewPager) {
Adapter adapter = new Adapter(getSupportFragmentManager());
adapter.addFragment(new ListContentFragment(), "Home");
adapter.addFragment(new TileContentFragment(), "Screen 1");
adapter.addFragment(new CardContentFragment(), "Screen 2");
adapter.addFragment(new ListContentFragment(), "Screen 3");
adapter.addFragment(new TileContentFragment(), "Screen 4");
adapter.addFragment(new CardContentFragment(), "Screen 5");
viewPager.setAdapter(adapter);
}
Run Code Online (Sandbox Code Playgroud)
我的XML
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content" …Run Code Online (Sandbox Code Playgroud) 在我的一个应用程序中,我正在使用标签布局和带有三个片段的viewpager.在每个片段中,我使用Java Rest API从服务器获取数据.此服务器数据取决于片段按钮单击.例如
在我点击播放按钮的过程片段中,然后该卡片视图进入已完成的片段,但它没有.当我刷新活动的时候,它意味着当活动关闭然后开始.我该怎么做来刷新片段?
rest android android-fragments android-recyclerview android-tablayout
我正在创建一个像instagram这样的简单项目,它的主要活动有3个标签。我想在tablayout标签中添加带有文本的图标,但是会引发异常。
我的主要活动
public class MainActivity extends AppCompatActivity {
TabLayout tabLayout;
ViewPager viewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewPager = (ViewPager) findViewById(R.id.viewPager);
tabLayout = (TabLayout) findViewById(R.id.tabLayout);
tabLayout.setupWithViewPager(viewPager);
TabLayout.Tab tab = tabLayout.getTabAt(0);
tab.setIcon(new IconicsDrawable(this).icon(FontAwesome.Icon.faw_home));
viewPager.setAdapter(new CustomAdapter(getSupportFragmentManager(), getApplicationContext()));
}
private class CustomAdapter extends FragmentPagerAdapter {
private String items[] = {"Home", "Upload", "Profile"};
public CustomAdapter(FragmentManager supportFragmentManager, Context applicationContext) {
super(supportFragmentManager);
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return new fragment1();
case 1:
return new fragment2();
case …Run Code Online (Sandbox Code Playgroud) android android-fragments android-viewpager android-tablayout