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

4nkexdtk  于 2023-02-27  发布在  Android
关注(0)|答案(1)|浏览(195)

活动:

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;
    }
}

我的问题与标签布局mTabs =(标签布局)布局. findViewById(R. id.标签);* * 因为布局**不被认为是一个限定词。我已经试着编造一些东西,但它仍然不起作用。谢谢。

gwbalxhn

gwbalxhn1#

限定符必须是表达式

在跳过路径根中的某些内容时显示。示例:

(错误):package.method(没有类)
(good例如:)包.类.方法**

相关问题