我目前无法仅使用 TabLayout 和 ViewPager 渲染 am 活动。我收到此错误:
Style ResourceReference{namespace=apk/res-auto, type=attr, name=textAppearanceButton} is not of type STYLE (instead attr)
从以下代码:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".CompoundInterest">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="409dp"
android:layout_height="wrap_content"
android:layout_marginTop="86dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.tabs.TabItem
android:id="@+id/tabAbout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="About" />
<com.google.android.material.tabs.TabItem
android:id="@+id/tabCalculator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculator" />
</com.google.android.material.tabs.TabLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tabLayout" />
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
我将 TabLayout 和 ViewPager 添加到一个空白的新布局中,即使在“连接”到片段之后,它们也从未呈现。
xml android android-layout android-design-library android-tablayout
我想滚动用户说明,但layout_scrollFlags ="滚动"不适用于RelativeLayout.ViewPager有2个片段,里面有SwipeRefreshLayout和RecyclerView.如何在CollapsingToolbar exitUntilCollapsed时滚出描述?
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/user_background"
android:layout_width="match_parent"
android:layout_height="192dp"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="@dimen/keyline_1">
<ImageView
android:id="@+id/avatar"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="@dimen/keyline_1"
android:layout_marginStart="@dimen/keyline_1" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/keyline_1"
android:layout_marginStart="@dimen/keyline_1"
android:layout_toEndOf="@id/avatar"
android:layout_toRightOf="@id/avatar"
android:orientation="vertical">
<TextView
android:id="@+id/full_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Body2" />
<TextView
android:id="@+id/screen_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
</LinearLayout>
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
<RelativeLayout
android:id="@+id/information"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll">
<TextView
android:id="@+id/bio"
android:layout_width="wrap_content" …Run Code Online (Sandbox Code Playgroud) android-design-library androiddesignsupport android-collapsingtoolbarlayout android-appbarlayout android-tablayout
我正在使用Android应用程序,我想在我的TableLayout中以编程方式添加TableRow.
我有这个TableLayout:
<TableLayout
android:id="@+id/details_table"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow>
<TextView
android:text="4686"
android:layout_width="wrap_content"
android:layout_column="0"
android:layout_weight="1"
android:textSize="7px"
android:textColor="@color/black" />
<TextView
android:text="sdhiuf osdfh isdhf ihdf"
android:layout_width="wrap_content"
android:layout_column="1"
android:layout_weight="1"
android:textSize="7px"
android:textColor="@color/black" />
<TextView
android:text="2"
android:layout_width="wrap_content"
android:layout_column="2"
android:layout_weight="1"
android:textSize="7px"
android:textColor="@color/black" />
<TextView
android:text="UN"
android:layout_width="wrap_content"
android:layout_column="3"
android:layout_weight="1"
android:textSize="7px"
android:textColor="@color/black" />
</TableRow>
Run Code Online (Sandbox Code Playgroud)
我想以编程方式添加这个TableRow.
我正在尝试这样的事情:
TableLayout detailsTable = (TableLayout) l.findViewById(R.id.details_table);
for(Nfce_Product nfceProduct : nfceProducts){
TableRow tableRow = new TableRow(getActivity());
TextView tvProductCode = new TextView(getActivity());
tvProductCode.setLayoutParams(new TableRow.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT, 1f));
tvProductCode.setText(nfceProduct.getProduct_code());
tvProductCode.setTextSize(TypedValue.COMPLEX_UNIT_PX, productDetailsTextSize);
tvProductCode.setTextColor(getResources().getColor(R.color.black));
TextView tvProductDescription = new TextView(getActivity());
tvProductDescription.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT, …Run Code Online (Sandbox Code Playgroud) 我有一个TabLayout连接到ViewPager.几乎所有东西都能正常工作:我可以看到标签,我可以浏览ViewPager中的页面并更新标签.
但是,我找不到如何允许用户单击选项卡以选择而不是滑动...
有谁知道怎么做?
我有一个导航抽屉和一个抽屉物品.Home是一个带有3个标签的View Pager.当我第一次打开View Pager选项卡时,一切正常,但是当我导航到其中一个Drawer 片段(比如个人资料)后导航回到它时,它是空的(所有三个选项卡)
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.TextView;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import com.example.amol.ecom.login.SessionManager;
import de.hdodenhof.circleimageview.CircleImageView;
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
DrawerLayout drawer;
FrameLayout frameLayout;
NavigationView navigationView;
ActionBarDrawerToggle toogle;
Fragment fragment;
NetworkImageView networkImageView;
public TextView nametextview, emailtextview;
@Override
protected …Run Code Online (Sandbox Code Playgroud) eclipse android android-viewpager android-volley android-tablayout
在我的项目中,我通过ViewPager创建我的tabBar,如下所示:
MainActivity.java
mViewPager = (ViewPager) findViewById(R.id.content_main_viewpager);
if ( mViewPager != null ) {
final ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.addFragment( new LandingSearch(), "" );
adapter.addFragment( new LandingWiki(), "" );
adapter.addFragment( new LandingForum(), "" );
mViewPager.setAdapter(adapter);
mViewPager.setOffscreenPageLimit( 3 );
final TabLayout tabs = (TabLayout) findViewById(R.id.content_main_tabs);
if ( tabs != null ) {
tabs.post(new Runnable() {
@Override
public void run() {
tabs.setupWithViewPager( mViewPager );
tabs.getTabAt(0).setIcon(R.drawable.ic_tab_search);
tabs.getTabAt(1).setIcon(R.drawable.ic_tab_favorite);
tabs.getTabAt(2).setIcon(R.drawable.ic_tab_forum);
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
app_bar_main.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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" …Run Code Online (Sandbox Code Playgroud) android android-fragments android-view android-viewpager android-tablayout
我使用了一个自定义TabLayout,ViewPager并且我在可滚动模式下使用TabLayout:
我需要它可以滚动,因为日期的数量可以变化到多达15-20:
<com.example.project.recommendedapp.CustomScrollableTabLayout
android:id="@+id/tab_layout_movie"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
app:tabGravity="fill"
app:tabMode="scrollable"
app:tabTextAppearance="?android:textAppearanceMedium"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
Run Code Online (Sandbox Code Playgroud)
我使用的自定义类是另一个类似的问题: 当tabMode设置为'scrollable'时,TabLayout没有填充宽度
该定制tablayout类是:
package com.example.project.recommendedapp;
import android.content.Context;
import android.graphics.Point;
import android.support.design.widget.TabLayout;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;
import java.lang.reflect.Field;
public class CustomScrollableTabLayout extends TabLayout {
private Context mContext;
Point size;
public CustomScrollableTabLayout(Context context) {
super(context);
mContext=context;
size = new Point();
}
public CustomScrollableTabLayout(Context context, AttributeSet attrs) {
super(context, attrs);
mContext=context;
size = new Point();
}
public CustomScrollableTabLayout(Context context, AttributeSet attrs, int …Run Code Online (Sandbox Code Playgroud) 
您好,我已经搜索了实现上图所示内容的可能方法,但是找不到任何帮助。我想创建一个TabLayout和底部导航,以便将TabLayout绑定到第一个底部图标,将第二个底部图标绑定到另一个TabLayout。
如果您可以提供示例或示例代码的帮助,我们将非常高兴。我还是一个初学者。
android android-fragments android-tablayout bottomnavigationview
以下是我目前得到的结果。
预期结果应该是其中三个作为第三个选项卡。
这就是我设置标签布局的方式。
可重用的方法,用于添加片段以查看分页器/选项卡的布局。
public void addFragmentToViewPager(Fragment fragment, String title, int imageRes) {
FragmentViewPagerAdapter fragmentViewPagerAdapter =
(FragmentViewPagerAdapter) mViewPager.getAdapter();
int position = fragmentViewPagerAdapter.addFragment(fragment, title);
fragmentViewPagerAdapter.notifyDataSetChanged();
View tabItemView = LayoutInflater.from(getContext()).inflate(R.layout.tab_item_child, null);
RoundedImageView roundImageView = (RoundedImageView) tabItemView.findViewById(R.id.childitem_riv);
roundImageView.setImageResource(imageRes);
TextView textView = (TextView) tabItemView.findViewById(R.id.childitem_tv_title);
textView.setText(title);
TabLayout.Tab tab = mTabLayout.getTabAt(position);
if (tab != null) {
Log.d(TAG,tab.getText()+"");
tab.setCustomView(tabItemView);
}
}
Run Code Online (Sandbox Code Playgroud)
我如何添加片段:
getView().addFragmentToViewPager(new ReusableMomentFragment(), "One", R.mipmap.ic_launcher);
getView().addFragmentToViewPager(new ReusableMomentFragment(), "Two", R.mipmap.ic_launcher);
getView().addFragmentToViewPager(new ReusableMomentFragment(), "Three", R.mipmap.ic_launcher);
Run Code Online (Sandbox Code Playgroud)
还有我的FragmentViewPagerAdapter:
public class FragmentViewPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new …Run Code Online (Sandbox Code Playgroud) 我有一个FragmentPagerAdapter处理获取当前片段,跟踪选项卡数量和设置每个选项卡的选项卡标题.
public class ClothingSectionsPagerAdapter extends FragmentPagerAdapter {
private String[] mCategories;
public ClothingSectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
public void setContext(Context context) {
mCategories = context.getResources().getStringArray(R.array.category);
}
@Override
public Fragment getItem(int position) {
return ClothingCategoryFragment.newInstance(mCategories[position]);
}
@Override
public int getCount() {
return mCategories.length;
}
@Override
public CharSequence getPageTitle(int position) {
Log.d("getPageTitle", mCategories[position]);
return mCategories[position];
}
}
Run Code Online (Sandbox Code Playgroud)
在我的活动中,我实现了这个类.
ClothingSectionsPagerAdapter sectionsPagerAdapter =
new ClothingSectionsPagerAdapter(getSupportFragmentManager());
sectionsPagerAdapter.setContext(this);
mViewPager.setAdapter(sectionsPagerAdapter);
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));
mTabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
mViewPager.setCurrentItem(startingFragmentPosition);
Run Code Online (Sandbox Code Playgroud)
但是当我运行我的应用程序时.标签存在,但它们是无标题.getPageTitle永远不会调用该方法.我该如何解决?