.java使用或覆盖已弃用的API。注意:使用-Xlint重新编译:弃用以获取详细信息

时间:2017-11-22 09:12:08

标签: java android gradle compilation warnings

我是Android新手。我开始了一个新的项目,并实现了一个介绍导航和应用程序抽屉屏幕。当我发布“APK”时,介绍滑块工作正常,“侧栏菜单”应用程序抽屉不起作用,应用程序崩溃,。

Gradle控制台有一条警告消息:

  

注意:   E:\ AndroidApps \ GoTogether \程序\ SRC \主\ java中的\ com \ softvision \ gotogether \程序\ WelcomeActivity.java   使用或覆盖已弃用的API。注意:重新编译   -Xlint:弃用细节。

如何使用-Xlint重新编译:Android Studio中的弃用?

这是我的代码:

package com.softvision.gotogether.app;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * Created by Shreekumar S [shreekumar.s@softvision.com] on 20-11-2017.
 */

public class WelcomeActivity extends AppCompatActivity {

    private PreferenceManager _preferences;
    private ViewPager _viewPager;
    private LinearLayout _linearDotsLayout;
    private Button _btnSkip, _btnNext;
    private int[] _slideLayouts;
    private TextView[] _textViewDots;

    private WelcomeViewPagerAdapter _welcomeViewPagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Checking for first time launch - before calling setContentView()
        _preferences = new PreferenceManager(this);
        if (!_preferences.IsFirstTimeLaunch()) {
            LaunchHomeScreen();
            finish();
        }

        // Making notification bar transparent
        if (Build.VERSION.SDK_INT >= 21) {
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        }
        setContentView(R.layout.activity_welcome);

        // get controls of Welcome screen
        _viewPager = (ViewPager)findViewById(R.id.welcomeViewPager);
        _linearDotsLayout = (LinearLayout) findViewById(R.id.welcomeLinearLayout);
        _btnSkip = (Button) findViewById(R.id.btnSkip);
        _btnNext = (Button) findViewById(R.id.btnNext);

        // layouts of all welcome sliders
        // add few more layouts if you want
        _slideLayouts = new int[]{
                R.layout.intro_slide_1,
                R.layout.intro_slide_2,
                R.layout.intro_slide_3,
                R.layout.intro_slide_4};

        // adding bottom dots
        AddBottomDots(0);

        // making notification bar transparent
        ChangeStatusBarColor();

        _welcomeViewPagerAdapter = new WelcomeViewPagerAdapter();
        _viewPager.setAdapter(_welcomeViewPagerAdapter);
        _viewPager.addOnPageChangeListener(onPageChangeListener);

        // On Skip button Click
        _btnSkip.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LaunchHomeScreen();
            }
        });

        // On Next button Click
        _btnNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // checking for last page
                // if last page home screen will be launched
                int current = GetItem(+1);
                if (current < _slideLayouts.length) {
                    // move to next screen
                    _viewPager.setCurrentItem(current);
                } else {
                    LaunchHomeScreen();
                }
            }
        });
    }

    private void LaunchHomeScreen() {
        _preferences.SetFirstTimeLaunch(false);

        // Move from Welcome Activity to Main Activity
        startActivity(new Intent(WelcomeActivity.this, MainActivity.class));

        finish();
    }

    private void AddBottomDots(int currentPage) {
        _textViewDots = new TextView[_slideLayouts.length];

        int[] colorsActive = getResources().getIntArray(R.array.array_dot_active);
        int[] colorsInactive = getResources().getIntArray(R.array.array_dot_inactive);

        _linearDotsLayout.removeAllViews();

        for (int i = 0; i < _textViewDots.length; i++) {
            _textViewDots[i] = new TextView(this);
            _textViewDots[i].setText(Html.fromHtml("&#8226;"));
            _textViewDots[i].setTextSize(35);
            _textViewDots[i].setTextColor(colorsInactive[currentPage]);
            _linearDotsLayout.addView(_textViewDots[i]);
        }

        if (_textViewDots.length > 0)
            _textViewDots[currentPage].setTextColor(colorsActive[currentPage]);
    }

    // Making notification bar transparent
    private void ChangeStatusBarColor() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
        }
    }

    private int GetItem(int i) {
        return _viewPager.getCurrentItem() + i;
    }

    // View pager adapter
    public class WelcomeViewPagerAdapter extends PagerAdapter {
        private LayoutInflater layoutInflater;

        public WelcomeViewPagerAdapter() {
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            View view = layoutInflater.inflate(_slideLayouts[position], container, false);
            container.addView(view);

            return view;
        }

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

        @Override
        public boolean isViewFromObject(View view, Object obj) {
            return view == obj;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            View view = (View) object;
            container.removeView(view);
        }
    }

    //  ViewPager change listener
    ViewPager.OnPageChangeListener onPageChangeListener = new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            AddBottomDots(position);

            // changing the next button text 'NEXT' / 'GOT IT'
            if (position == _slideLayouts.length - 1) {
                // last page. make button text to GOT IT
                _btnNext.setText(getString(R.string.start));
                _btnSkip.setVisibility(View.GONE);
            } else {
                // still pages are left
                _btnNext.setText(getString(R.string.next));
                _btnSkip.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    };
}

0 个答案:

没有答案