加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 错误:“限定符必须是表达式” – Android Studio

发布时间:2020-12-15 02:12:49 所属栏目:Java 来源:网络整理
导读:活动: public class PreviewsFragment extends Fragment {private ViewPager mPager;@Overridepublic View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) { ViewGroup root = (ViewGroup) inflater.inflate(R.layo
活动:

public class PreviewsFragment extends Fragment {

private ViewPager mPager;

@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.section_all_icons,container,false);

    ActionBar toolbar = ((AppCompatActivity) getActivity()).getSupportActionBar();
    if (toolbar != null)
        toolbar.setTitle(R.string.section_two);

    mPager = (ViewPager) root.findViewById(R.id.pager);
    mPager.setAdapter(new MyPagerAdapter(getActivity().getSupportFragmentManager()));

    TabLayout mTabs = (TabLayout) layout.findViewById(R.id.tabs); //layout: qualifier must be an expression.
    mTabs.setupWithViewPager(mPager);
    mTabs.setTabTextColors(getResources().getColor(R.color.semitransparent_white),getResources().getColor(android.R.color.white));
    mTabs.setSelectedTabIndicatorColor(getResources().getColor(R.color.accent));
    mTabs.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            mPager.setCurrentItem(tab.getPosition());
        }

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

        }

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

        }
    });

    return root;
}

@Override
public void onResume() {
    super.onResume();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Toolbar appbar = (Toolbar) getActivity().findViewById(R.id.toolbar);
        appbar.setElevation(0);
    }
}

@Override
public void onPause() {
    super.onPause();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Toolbar appbar = (Toolbar) getActivity().findViewById(R.id.toolbar);
        appbar.setElevation((int) getResources().getDimension(R.dimen.toolbar_elevation));
    }
}

class MyPagerAdapter extends FragmentStatePagerAdapter {

    final String[] tabs;

    public MyPagerAdapter(android.support.v4.app.FragmentManager fm) {
        super(fm);
        tabs = getResources().getStringArray(R.array.tabs);
    }

    @Override
    public Fragment getItem(int position) {
        Fragment f = new Fragment();
        switch (position) {
            case 0:
                f = IconsFragment.newInstance(R.array.latest);
                break;
            case 1:
                f = IconsFragment.newInstance(R.array.system);
                break;
            case 2:
                f = IconsFragment.newInstance(R.array.google);
                break;
            case 3:
                f = IconsFragment.newInstance(R.array.games);
                break;
            case 4:
                f = IconsFragment.newInstance(R.array.icon_pack);
                break;
            case 5:
                f = IconsFragment.newInstance(R.array.drawer);
                break;
        }
        return f;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return tabs[position];
    }

    @Override
    public int getCount() {
        return tabs.length;
    }
}

我有TabLayout mTab??s =(TabLayout)layout.findViewById(R.id.tabs)的问题;因为布局不被视为限定符.我试图做些什么,但它仍然不起作用.
谢谢.

解决方法

限定符必须是表达式

***Appears when you skipped something in the root of the path. Exemple:***

(错误):package.method(没有类)

(好的例子:) package.class.method **

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读