有很多关于添加库和依赖项的信息,但是我无法找到有关能够实际编辑库的任何有用信息.
我在我的项目中添加了https://github.com/jdamcd/android-crop作为依赖项,但我想编辑它的一些功能,主要是布局相关的东西.但是,当我进入浏览文件时,Android Studio会说"生成并且不应该编辑构建文件夹下的文件",当我编辑它们时,一旦系统构建,它们就会返回到预编辑状态.
我也尝试在notepad ++中编辑文件,并出现同样的问题(它们会在构建时返回到预编辑状态).
有人可以告诉我如何编辑库或解决方法,我可以更改布局/一些java,而无需将整个库复制并粘贴到我的项目中以使其可编辑?
提前致谢,
上帝的速度.
编辑:答案是使用以下代码简单地将库作为依赖项添加到build.gradle文件中:compile'com.soundcloud.android:android-crop:0.9.10@aar'
您必须将其添加为模块而不仅仅是外部依赖项,然后您可以编辑文件.
如果有人想知道如何遵循这些步骤:
settings.gradle类似的内容中:
include ':LibraryContainingFolder:ActualLibFolder'我正在尝试设置Dagger 2.12,我收到此错误:
错误:使用了@ dagger.android.ContributesAndroidInjector,但在处理器路径上找不到dagger.android.processor.AndroidProcessor
这是我配置Dagger的方式:
我的应用类:
public final class App extends android.app.Application implements HasActivityInjector {
@Inject
DispatchingAndroidInjector<Activity> activityInjector;
@Override
public void onCreate() {
super.onCreate();
DaggerAppComponent.builder().build().inject(this);
}
@Override
public AndroidInjector<Activity> activityInjector() {
return activityInjector;
}
}
Run Code Online (Sandbox Code Playgroud)
ActivityBindingModule:
@Module
public abstract class ActivityBindingModule {
@ContributesAndroidInjector(modules = SearchActivityModule.class)
abstract SearchActivity searchActivity();
}
Run Code Online (Sandbox Code Playgroud)
SearchActivityModule:
@Module
public class SearchActivityModule {
@Provides
public SearchActivityDelegate getDelegate(SearchActivity searchActivity) {
return searchActivity;
}
@Provides
public SearchActivityPresenter providePresenter(SearchActivity searchActivity) {
return new SearchActivityPresenter(new OtherDependency(), searchActivity);
}
}
Run Code Online (Sandbox Code Playgroud)
的AppModule:
@Module(includes = …Run Code Online (Sandbox Code Playgroud) 我有一个使用GridLayoutManager实现的RecyclerView.
根据数据集中的项目数量,spanCount介于1-4之间.项目宽度根据spanCount而变化.如果spancount为4或更高,则spanCount保留为4.
如果我有5个项目,则剩下1个项目(1行中有4个项目,剩下1个项目),位于屏幕左侧,单独排成一行.我希望它集中在一起.
我已经尝试以编程方式设置左侧项目的边距,并将recyclerView和各个项目包装在LinearLayouts中,并将重力设置为居中,以及设置recyclerView的重力.
示例项XML:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal"
>
<RelativeLayout
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:id="@+id/relative"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
示例RecyclerView XML
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议一个解决方案,或者给我一些工作材料.
提前致谢.
android margin centering gridlayoutmanager android-recyclerview
这是我的 XML 的基本模型:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/background_colour"
>
<android.support.design.widget.AppBarLayout
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:id="@+id/profile_screen_appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true"
android:minHeight="150dp"
>
<android.support.design.widget.CollapsingToolbarLayout
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
android:id="@+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:expandedTitleMarginTop="32dp"
app:expandedTitleMarginBottom="32dp"
app:expandedTitleMarginEnd="4dp"
app:expandedTitleMarginStart="32dp"
android:minHeight="100dp"
>
<android.support.v7.widget.Toolbar
android:minHeight="100dp"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:background="@color/fab_material_red_500"
>
</android.support.v7.widget.Toolbar>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/blue"
>
<!-- the ViewPager is programatically set to be have the height and width equivalent to that of the screen width of the device --> <com.example.heavymagikhq.MyViewPager
android:padding="0dp"
android:fitsSystemWindows="true"
android:id="@+id/viewPager"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_scrollFlags="scroll|enterAlways"/>
/>
</RelativeLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout> …Run Code Online (Sandbox Code Playgroud) java android android-recyclerview android-coordinatorlayout android-collapsingtoolbarlayout
我从Firebase崩溃报告中收到了这个堆栈跟踪:
Exception java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.toLowerCase(java.util.Locale)' on a null object reference
bsz.d (:com.google.android.gms.DynamiteModulesC:6098)
bta.run (:com.google.android.gms.DynamiteModulesC:1028)
java.lang.Thread.run (Thread.java:818)
崩溃发生在运行API 23的设备上.
与其他一些堆栈跟踪不同,这个没有提到发生崩溃的Activity.
堆栈跟踪表明错误已连接到Google Play服务.在我的应用中,我使用的是Google Play服务版本9.4.0.
以下是我使用的GMS和Firebase库:
compile 'com.google.android.gms:play-services-places:9.4.0'
compile 'com.google.android.gms:play-services-plus:9.4.0'
compile 'com.google.android.gms:play-services-auth:9.4.0'
compile 'com.google.android.gms:play-services-gcm:9.4.0'
compile 'com.google.android.gms:play-services-location:9.4.0'
compile 'com.google.android.gms:play-services-maps:9.4.0'
compile 'com.google.firebase:firebase-core:9.4.0'
compile 'com.google.firebase:firebase-database:9.4.0'
compile 'com.google.firebase:firebase-auth:9.4.0'
compile 'com.google.firebase:firebase-storage:9.4.0'
compile 'com.google.firebase:firebase-crash:9.4.0'
Run Code Online (Sandbox Code Playgroud)
我一直没能找到类似的问题.但DynamiteModules似乎与Firebase有关.
有谁知道导致这次崩溃的原因是什么?
提前致谢.
java android firebase google-play-services android-6.0-marshmallow
以下是我尝试上传文件的两种方法:
1.
getURLOfPhoto(assetURL: imagesDictionary[String(whichProfileImage)]! , completionHandler: { (responseURL) in
FIRStorage.storage().reference().putFile(responseURL as! URL)
})
Run Code Online (Sandbox Code Playgroud)
2.
let assets = PHAsset.fetchAssets(withALAssetURLs: [imagesDictionary[String(whichProfileImage)] as! URL], options: nil)
let asset = assets.firstObject
asset?.requestContentEditingInput(with: nil, completionHandler: { (contentEditingInput, info) in
let imageFile = contentEditingInput?.fullSizeImageURL?
FIRStorage.storage().reference().child("test").putFile(imageFile!, metadata: nil) { (metadata, error) in
if let error = error {
return
}
}
})
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Body file is unreachable: /var/mobile/Media/DCIM/100APPLE/picture.JPG
Error Domain=NSCocoaErrorDomain Code=257 "The file “picture.JPG” couldn’t be opened because you don’t have permission to view it."
UserInfo={NSURL=file:///var/mobile/Media/DCIM/100APPLE/picture.JPG, NSFilePath=/var/mobile/Media/DCIM/100APPLE/picture.JPG, …Run Code Online (Sandbox Code Playgroud) 当我第一次运行我的应用程序时,模拟器能够在应用程序位于前台时显示通知。
当我重新启动应用程序didReceive notification:(即 iOS 9 中的通知方法)时,将调用willPresent notification(即 iOS 10 中的通知方法),并且当应用程序位于前台时不会显示任何通知。但是,如果应用程序在后台运行,则会显示通知。
我使用以下代码获得通知授权:
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]? = [:]) -> Bool {
if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound, .sound]) { (granted, error) in
UNUserNotificationCenter.current().delegate = self
}
}
return true
}
Run Code Online (Sandbox Code Playgroud)
我已经实现了 willPresent 通知方法:
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) completionHandler(UNNotificationPresentationOptions.alert)
} …Run Code Online (Sandbox Code Playgroud) ios uilocalnotification ios-simulator swift unusernotificationcenter
我的应用程序已在Google登录过程中开始崩溃。
以前没有像这样崩溃。
是否可以连接到更改Google Play服务版本?
还有什么可能导致此崩溃?
我可以通过延迟在Application类中实现OneSignal初始化之前停止它。但是,我不确定它们是如何连接的,只是由于反复试验,才发现它们之间的连接。更改OneSignal实现似乎不是一个合适的解决方案,因为它回避了以前没有发生过的问题,如果我找不到更具体的原因,可能会再次发生。
此外,崩溃并不总是在登录过程中发生。
logcat的主要线索似乎是:
An error occurred while executing doInBackground()
Caused by: java.util.ConcurrentModificationException
at com.google.android.gms.auth.api.signin.internal.zzb.zzafx(Unknown Source)
at com.google.android.gms.auth.api.signin.internal.zzb.loadInBackground(Unknown Source)
Run Code Online (Sandbox Code Playgroud)
这是完整的日志:
UncaughtException: java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.support.v4.content.ModernAsyncTask$3.done(ModernAsyncTask.java:142)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.util.ConcurrentModificationException
at java.util.WeakHashMap$HashIterator.next(WeakHashMap.java:165)
at com.google.android.gms.auth.api.signin.internal.zzb.zzafx(Unknown Source)
at com.google.android.gms.auth.api.signin.internal.zzb.loadInBackground(Unknown Source)
at android.support.v4.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:296)
at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:54)
at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:42)
at android.support.v4.content.ModernAsyncTask$2.call(ModernAsyncTask.java:128)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818) `11-11 00:35:53.023 11247-11903/com.example.package E/AndroidRuntime: FATAL EXCEPTION: ModernAsyncTask …Run Code Online (Sandbox Code Playgroud) android android-asynctask google-play-services onesignal google-signin
如果我在视图上调用 setPadding() ,我可以成功设置填充,但是,如果我先设置 layoutParams 然后设置填充,或者设置填充然后设置 layoutParams,则不会应用填充。
示范:
//This doesn't work
textView.setLayoutParams(linearLayoutParams);
textView.setPadding(0, 100, 0 , 0);
//This doesn't work either
testView.setPadding(0, 100, 0 , 0);
textView.setLayoutParams(linearLayoutParams);
//This does work
textView.setPadding(0, 100, 0 , 0);
Run Code Online (Sandbox Code Playgroud)
有谁知道如何同时使用 setLayoutParams() 和 setPadding(),或者为什么 setLayoutParams() 会阻止 setPadding() 工作?
编辑:更多细节:
我在 onCreate() 中调用这个方法
public void initTextView(){
Textview textView = (TextView) findViewById(R.id.textView);
LinearLayout.LayoutParams linearLayoutParams = new LinearLayout.LayoutParams(myWidth, myHeight);
textView.setLayoutParams(linearLayoutParams);
//This doesn't work
textView.setPadding(0, 100 ,0 , 0);
}
Run Code Online (Sandbox Code Playgroud)
但如果我从上面注释掉这一行:
// textView.setLayoutParams(linearLayoutParams);
Run Code Online (Sandbox Code Playgroud)
然后 setPadding() 方法起作用了。
提前致谢。
我一直在尝试为我的应用设置谷歌登录.
我按照这里的教程:
https://developers.google.com/identity/sign-in/android/start-integrating
我做了一切.我可以登录登录并退出.
然后我添加了一个异步任务来获取一个令牌,它似乎成功检索.它实现如下:
private class GetIdTokenTask extends AsyncTask<Void, Void, String> {
private static final String SERVER_CLIEdNT_ID = "749433126040-ca4gfj7ucuh0m2suo3230u03o3d7doni.apps.googleusercontent.com";
@Override
protected String doInBackground(Void... params) {
String accountName = Plus.AccountApi.getAccountName(mGoogleApiClient);
Account account = new Account(accountName, GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
String scopes = "audience:server:client_id:" + SERVER_CLIEdNT_ID; // Not the app's client ID.
try {
return GoogleAuthUtil.getToken(getApplicationContext(), account, scopes);
} catch (IOException e) {
Log.e(TAG, "Error retrieving ID token.", e);
return null;
} catch (GoogleAuthException e) {
Log.e(TAG, "Error retrieving ID token. Google exception", e); …Run Code Online (Sandbox Code Playgroud) 我在故事板中设置了辅助功能标识符.这些都有效.但是,我在更多视图上启用了辅助功能,现在使用辅助功能标识符找不到任何元素.
但是,我仍然可以使用记录功能生成的代码找到元素.
这是我如何找到元素:
XCUIApplication().buttons["loginButton"] //loginButton is the accessibility identifier
Run Code Online (Sandbox Code Playgroud)
以下是使用录像机找到相同按钮的方法:
XCUIApplication().children(matching: .window).element(boundBy: 0).children(matching:
.other).element.children(matching: .other).element.children(matching:
.other).element.children(matching: .other).element.tap()
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
No matches found for *typeOfElement*
Run Code Online (Sandbox Code Playgroud)
到目前为止,我还无法在线找到适用的解决方案.
我的问题简而言之:为什么我不能使用可访问性标识符来获取元素的引用.
提前致谢.