英文:
error: cannot find symbol import androidx.core.widget.SwipeRefreshLayout; after migrating to androidx
问题
当我迁移到AndroidX时出现以下错误:
错误 - 错误:找不到符号
import androidx.core.widget.SwipeRefreshLayout;
^
符号: 类 SwipeRefreshLayout
位置: 包 androidx.core.widget
这是我的代码详情,请帮忙解决...
package com.app.exammantra.activities;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import androidx.core.widget.SwipeRefreshLayout; // 错误发生在这一行
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnKeyListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import com.app.exammantra.Config;
import com.app.exammantra.R;
import com.app.exammantra.utilities.GDPR;
import com.google.ads.mediation.admob.AdMobAdapter;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
public class ActivityPdfView extends AppCompatActivity {
// 代码内容...
}
// build.gradle 文件...
希望对您有所帮助。
英文:
when i migrate to androidx then
error - error: cannot find symbol
import androidx.core.widget.SwipeRefreshLayout;
^
symbol: class SwipeRefreshLayout
location: package androidx.core.widget
here is my code details, Please help me ....
package com.app.exammantra.activities;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import androidx.core.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnKeyListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import com.app.exammantra.Config;
import com.app.exammantra.R;
import com.app.exammantra.utilities.GDPR;
import com.google.ads.mediation.admob.AdMobAdapter;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
public class ActivityPdfView extends AppCompatActivity {
int position;
WebView webview;
String str_title, str_url;
SwipeRefreshLayout swipeRefreshLayout;
private AdView adView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pdf_view);
if (Config.ENABLE_RTL_MODE) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}
}
swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setColorSchemeResources(R.color.orange, R.color.green, R.color.blue, R.color.red);
swipeRefreshLayout.setEnabled(false);
Intent intent = getIntent();
position = intent.getIntExtra("POSITION", 0);
str_title = intent.getStringExtra("TITLE");
str_url = intent.getStringExtra("URL");
//Toast.makeText(this, str_url, Toast.LENGTH_SHORT).show();
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(str_title);
}
loadBannerAd();
webview = (WebView) findViewById(R.id.webView);
// web settings
webview.getSettings().setDefaultTextEncodingName("UTF-8");
webview.setFocusableInTouchMode(false);
webview.setFocusable(false);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setBuiltInZoomControls(false);
webview.getSettings().setSupportZoom(true);
webview.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return true;
}
});
webview.setLongClickable(false);
//webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webview.setWebViewClient(new myWebClient());
webview.loadUrl("https://docs.google.com/gview?embedded=true&url=" + str_url);
webview.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
webview.goBack();
return true;
}
return false;
}
});
}
public class myWebClient extends WebViewClient {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
swipeRefreshLayout.setRefreshing(true);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
swipeRefreshLayout.setRefreshing(false);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(getApplicationContext(), "Failed to Connect Network!",Toast.LENGTH_LONG).show();
view.loadUrl("about:blank");
}
}
@Override
public void onBackPressed() {
onFinishReadBook();
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case android.R.id.home:
onBackPressed();
break;
default:
return super.onOptionsItemSelected(menuItem);
}
return true;
}
public void loadBannerAd() {
if (Config.ENABLE_ADMOB_BANNER_ADS) {
MobileAds.initialize(ActivityPdfView.this, getResources().getString(R.string.admob_app_id));
adView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,GDPR.getBundleAd(ActivityPdfView.this)).build();
adView.loadAd(adRequest);
adView.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
}
@Override
public void onAdFailedToLoad(int error) {
adView.setVisibility(View.GONE);
}
@Override
public void onAdLeftApplication() {
}
@Override
public void onAdOpened() {
}
@Override
public void onAdLoaded() {
adView.setVisibility(View.VISIBLE);
}
});
}
}
public void onFinishReadBook() {
AlertDialog.Builder dialog = new AlertDialog.Builder(ActivityPdfView.this);
dialog.setTitle(R.string.title_dialog_finish_reading);
dialog.setMessage(getString(R.string.msg_dialog_finish_reading));
dialog.setPositiveButton(getString(R.string.option_yes), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
finish();
}
});
dialog.setNegativeButton(getString(R.string.option_cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
dialog.setCancelable(false);
dialog.show();
}
}
My build.gradle file
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/'}
}
dependencies {
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.6'
}
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
repositories {
maven { url 'https://maven.google.com' }
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 30
defaultConfig {
applicationId 'com.app.exammantra'
manifestPlaceholders = [onesignal_app_id: "75e9ef33-cc67-4ae3-8b4f-1ab09c874ae1",
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: "REMOTE"]
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.google.android.gms:play-services-ads:19.4.0'
implementation 'com.google.firebase:firebase-core:17.5.0'
implementation 'com.google.firebase:firebase-messaging:20.2.4'
implementation 'com.balysv:material-ripple:1.0.2'
implementation 'com.onesignal:OneSignal:3.15.3'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'com.google.android.ads.consent:consent-library:1.0.8'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
}
apply plugin: 'com.google.gms.google-services'
i googled it and try some ans but not getting any solution. Hope here i got it.
答案1
得分: 0
正确的包是:
androidx.swiperefreshlayout.widget.SwipeRefreshLayout
链接:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论