当我在Android Studio 2中运行应用程序时,我遇到了构建错误.当我使用早期版本的Android Studio时,这些错误并不存在.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.squareup.haha.guava.base.Joiner$1) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* …Run Code Online (Sandbox Code Playgroud) 我正在尝试实现活动转换,但我无法看到效果.这是我的第一个活动的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_architecture);
setUpWindowAnimations();
}
private void setUpWindowAnimations() {
if (android.os.Build.VERSION.SDK_INT >= 21) {
Log.i("ANIM", "Fade called");
Fade fade = new Fade(2);
fade.setDuration(3000);
getWindow().setExitTransition(fade);
}
}
Run Code Online (Sandbox Code Playgroud)
这是第二个活动的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image);
setUpWindowAnimations();
}
private void setUpWindowAnimations() {
if (android.os.Build.VERSION.SDK_INT >= 21) {
Log.i("ANIM", "slide called");
Slide slide = new Slide(Gravity.LEFT);
slide.setDuration(3000);
getWindow().setEnterTransition(slide);
}
}
Run Code Online (Sandbox Code Playgroud)
尽管我已经设置淡出动画,但没有淡入淡出,幻灯片也以默认方式工作,即方向是BOTTOM而不是LEFT.
这是我的values/style.xml,这是我的v21/styles.xml.
这是我的AndroidManifest.xml:
<application
android:name=".MyApplication"
android:allowBackup="true"
android:hardwareAccelerated="true" …Run Code Online (Sandbox Code Playgroud) 我有一个简单的任务:我想跟踪应用安装的引用ID并将其传递给后端.
我做了什么:我创建了一个带有额外参数的链接,referrer并将其附加到邀请链接.当它打开时,javascript检测浏览器是否是Android移动浏览器,然后准备intent并发出重定向到该意图.在准备意图时,referrer字段从网址中提取并附加到intent以下内容中:
intent://scan/#Intent;scheme=com.example.android;package=com.example.android&referrer=4;end
Run Code Online (Sandbox Code Playgroud)
这是我的代码BroadCastReceiver:
public class InstallReferrerReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
TinyDB tinyDB = new TinyDB(context);
String referrer = intent.getStringExtra("referrer");
tinyDB.putString(AppConstants.REFERRAL_ID, referrer);
tinyDB.putBoolean(AppConstants.REFERRAL_SENT, false);
}
}
Run Code Online (Sandbox Code Playgroud)
所以,我期望在这里得到的价值referrer是4基于上述intent.但我得到的价值就是这个字符串utm_source=google-play&utm_medium=organic
我做错了什么,如何修复它以获得正确的referrer字段值?
编辑
referrer安装应用程序后,我在创建URL或从字段中提取值时没有任何问题.
通过点击任意按钮或直接在移动浏览器中打开邀请链接后,我使用上述内容"如果已经安装了应用程序,请打开应用程序,或者在Play商店应用程序上打开应用程序页面以供用户安装".
问题是,我应该如何通过上述意图将referrer字段的值从邀请链接传递到Play商店应用,以便Play商店收到此值并在安装时将其传递给应用.
android android-intent install-referrer android-broadcastreceiver
我有一个ListView,每个项目都是水平的RecyclerView.我面临的问题是,水平滚动不是很平滑.如果我在一个完全水平的方向上滚动/滑动,那么它工作正常,但如果滚动甚至略微非水平(比如与水平成10度角),它认为上/下滚动而不是左/右,由于父母ListView.我试过这个方法:
recyclerView.setOnTouchListener(new FlingRecyclerView.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow ScrollView to intercept touch events.
v.getParent().requestDisallowInterceptTouchEvent(true);
Log.i("Scroll down", "Intercept true");
break;
case MotionEvent.ACTION_UP:
// Allow ScrollView to intercept touch events.
v.getParent().requestDisallowInterceptTouchEvent(false);
break;
case MotionEvent.ACTION_MOVE:
// Allow ScrollView to intercept touch events.
v.getParent().requestDisallowInterceptTouchEvent(true);
break;
}
// Handle HorizontalScrollView touch events.
v.onTouchEvent(event);
return true;
}
});
Run Code Online (Sandbox Code Playgroud)
但它不是很有效.事实上,我没有注意到很多改进.那是因为只有当动作完全水平时才会调用此动作事件 - 这种情况已经正常工作了.然后我尝试这样做:
class MyGestureDetector extends GestureDetector.SimpleOnGestureListener …Run Code Online (Sandbox Code Playgroud) android listview scroll user-experience android-recyclerview
使用案例:将后台队列中的图像上传到服务器,图像可以是存储在手机内存中的网址或图像文件.
我想要的是将队列中的项目数量限制为3并将模糊图像显示为在活动中的回收站视图中上载的实际图像的占位符,每个占位符上都有一个进度条指示已上载了多少内容.在每个占位符的顶部有三个按钮,可以暂停,取消或恢复上传图像.
现状:现在,我是用Multipart在Retrofit 1.9.0上传图片和该服务呼叫在活动中完成的.
我无法弄清楚如何使用Retrofit或任何其他库来取消,暂停或恢复多部分POST请求以及如何将UI事件与api服务线程联系起来.我可以从服务更新UI,但是如何从UI中的事件(暂停/恢复/取消)更新服务中的某些内容?
我该如何处理这个用例?我需要使用服务吗?我可以根据服务中执行的请求在其他活动中显示进度指示器吗?这个过程的架构应该是什么?我不需要它的代码,但是如果有一些与此相关的有用的引用,我想阅读并测试它以最终得出我的方法.
今天我将所有支持库和buildtools更新到最新版本以支持Android N.一旦我更新了所有内容并运行了应用程序,我的应用程序中的InstanceId生成方法出错了GCM.所以,我搜索并找到了建议更新播放服务的解决方案.在完成所有SO问题和答案后,我陷入困境,无法前进.切换回支持库23.x.x不是一个选项,因为我想定位Android N.
以下是我的项目级build.gradle文件的外观:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
Run Code Online (Sandbox Code Playgroud)
应用级别build.gradle:
buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
// maven { url 'http://hansel.io/maven' }
maven {
url "https://jitpack.io"
}
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
// classpath 'io.hansel.preprocessor:preprocessor:1.0.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
//apply plugin: 'io.hansel.preprocessor'
android { …Run Code Online (Sandbox Code Playgroud) android google-play-services android-studio android-gradle-plugin
我在我的应用程序中使用Crashlytics,我希望获得用户ID和电子邮件以及每次崩溃.我做了这样的事情:
Crashlytics.setUserEmail(tokenModel.getEmail());
Crashlytics.setUserIdentifier(String.valueOf(tokenModel.getPk()));
Run Code Online (Sandbox Code Playgroud)
我在登录屏幕上执行此操作,用户提供了他的电子邮件并成功注册了应用程序,以获取用户ID.问题是,我没有在崩溃报告中获取这些数据.
在上述背景下,Crashlytics的生命周期和工作是什么?每次应用程序打开时是否需要设置这些字段?
我有一个RecyclerView用来显示2列布局的图表,其中某些项目作为部分使用全宽显示。这就是我设置我的方式RecyclerView:
StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS);
recyclerView.setItemAnimator(null);
recyclerView.setLayoutManager(layoutManager);
recyclerView.addItemDecoration(new SpacesItemDecoration(Utils.dpToPx(8)));
Run Code Online (Sandbox Code Playgroud)
这是我的SpaceItemDecoration课:
private class SpacesItemDecoration extends RecyclerView.ItemDecoration {
private int space;
public SpacesItemDecoration(int space) {
this.space = space;
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
int position = parent.getChildAdapterPosition(view);
int viewType = adapter.getItemViewType(position);
if (viewType == 1) {
//this is the regular view type
if (map.get(position)) {
//it is on the left side
outRect.right = space / …Run Code Online (Sandbox Code Playgroud) android staggered-gridview android-recyclerview recyclerview-layout
我的应用程序中有许多布局TextView用于显示从后端获取的一些句子。问题是,有时要显示的文本包含一些英文词典中没有的词,所以我在这些词下方有一个红色下划线。这看起来很糟糕。我看过其他关于相同的 SO 帖子,人们建议使用:
android:inputType="textNoSuggestion"
Run Code Online (Sandbox Code Playgroud)
在 .xml 中TextView。但是,我从 Android Studio 收到一条警告,即 inputType 只能用于输入EditText或其他类似的视图,我想这是正确的。
那么,是否有任何TextView特定属性可用于禁用拼写检查?是否有任何全局设置我可以放在禁用拼写检查的应用程序中,因为TextView使用某些属性重构每个设置似乎需要做很多工作。
我有一个EditText,Activity我希望它是活动的,当我打开它时,软键盘会打开Activity.这是我xml的EditText:
<EditText
android:background="@null"
android:cursorVisible="true"
android:elegantTextHeight="true"
android:enabled="true"
android:focusable="true"
android:hint="Search"
android:id="@+id/editText11"
android:inputType="textNoSuggestions|textCapSentences"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:singleLine="true"
android:textColor="#000000"
android:textCursorDrawable="@null" />
Run Code Online (Sandbox Code Playgroud)
我已经习惯android:windowSoftInputMode="stateVisible"了这项活动EditText.
问题是,当我按back一次键盘时,键盘不会隐藏(理想情况下它会在所有其他键盘中隐藏EditText),当我back再次按下键盘时,键盘会关闭Activity.在第一次back按下时,我没有接到onBackPressed()第二次back按下的电话,我这样做.为什么会发生这种行为以及如何解决?
编辑我想要的是,如果键盘打开,按下键应关闭键盘,如果键盘未打开,则关闭活动.
android android-manifest android-softkeyboard android-edittext