我正在为我的Android应用程序开发一个帐户管理活动,但是我很难弄清楚为什么来自微调器的setSelection()方法不会触发附加到所述Spinner的OnItemSelectedListener.
这就是我目前所拥有的;
onCreate()方法:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.account_management);
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
retreiveLanguage();
initializeUI();
// Vérification si l'usager est déjà connecté
Globals appState = ((Globals) this.getApplication());
boolean userLoggedIn = appState.isUserLoggedIn();
boolean userInfoAvailable = appState.isUserInfoAvailable();
if (userLoggedIn && userInfoAvailable) {
fillUI();
}
}
Run Code Online (Sandbox Code Playgroud)
来自initializeUI()方法的相关行,该方法在Activity的创建中调用,该方法显示Spinner与Listener的绑定:
/** OnItemSelectedHandler for the Country Spinner */
mCountrySpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
Log.i(TAG, "onCountrySelected() was called, position : " + pos);
mProvinces = new ArrayList<String>();
mProvincesCode …Run Code Online (Sandbox Code Playgroud) 我在 android studio 中创建了一个新的 flutter 项目,然后“打开项目”它的 android 部分,我在 MainActivity.kt 中遇到了一个错误,但是它构建成功。
我的课程路径是:
最后我的依赖项是:
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.70"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Run Code Online (Sandbox Code Playgroud)
如果有人可以帮助我,我将不胜感激。
我正在使用Action Bar Compat,因此带导航抽屉的操作栏向下兼容到API级别9,我想更改操作栏的背景.
我复制了Android开发者的代码:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">@drawable/actionbar_background</item>
<!-- Support library compatibility -->
<item name="background">@drawable/actionbar_background</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
这就是问题所在.
当我将图像绘制或颜色作为背景时,它工作正常.但是我想将背景定义为渐变形状,所以我actionbar_background看起来像:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<gradient
android:startColor="@color/ac_bg_start"
android:endColor="@color/ac_bg_end"
android:type="linear"/>
<size
android:width="1dp"
android:height="48dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
我希望它以水平方式重复,但即使这样也会导致错误,实际上是非常有趣的错误.当我尝试运行应用程序时,测试设备甚至模拟器都会重新启动.DeadObjectException在重新启动之前我能够捕获.
背景画如何看起来像?
我的应用未在Google Play Console中将Nexus 6列为受支持的设备.
我阅读了为Nexus 6和Nexus 9准备好应用程序的博客文章:
Nexus 6的量化密度为560 dpi,介于xxhdpi和xxxhdpi主密度桶之间.
关于我的问题有一个段落:
确保您未在Google Play上过滤
如果您正在使用AndroidManifest.xml文件中的元素,那么您应该停止使用它,因为每次新设备出来时,它都无法扩展以重新编译和发布您的应用程序.但是,如果必须使用它,请确保更新清单以添加这些设备的配置(按屏幕大小和密度).否则,您的应用可能会被排除在这些设备上的Google Play搜索结果中.
好吧,我必须使用,<compatible-screens>因为我试图从平板电脑中排除我的应用程序.
我<compatible-screens>在Manifest中的当前元素看起来像:
<compatible-screens>
<!-- small size screens -->
<screen
android:screenDensity="ldpi"
android:screenSize="small" />
<screen
android:screenDensity="mdpi"
android:screenSize="small" />
<screen
android:screenDensity="hdpi"
android:screenSize="small" />
<screen
android:screenDensity="xhdpi"
android:screenSize="small" />
<screen
android:screenDensity="480"
android:screenSize="small" />
<!-- normal size screens -->
<screen
android:screenDensity="ldpi"
android:screenSize="normal" />
<screen
android:screenDensity="mdpi"
android:screenSize="normal" />
<screen
android:screenDensity="hdpi"
android:screenSize="normal" />
<screen
android:screenDensity="xhdpi"
android:screenSize="normal" />
<screen
android:screenDensity="480"
android:screenSize="normal" />
<screen
android:screenDensity="640"
android:screenSize="normal" /> …Run Code Online (Sandbox Code Playgroud) 我有代码
private List<Field> subFields;
private Collection<Field> subFieldsCollection;
...
try {
if (subFields == null && subFieldsCollection != null && !subFieldsCollection.isEmpty()) {
subFields = new ArrayList<>();
subFields.addAll(subFieldsCollection);
}
} catch (IllegalStateException e) {
...
}
Run Code Online (Sandbox Code Playgroud)
而且我想知道它怎么会IllegalStateException被扔掉.它显然发生在我的应用程序的用户身上,但我无法追踪错误.
文件Collection.addAll()说:
IllegalArgumentException - 如果由于插入限制,此时不能添加所有元素
但是什么是插入限制?
我想这取决于集合的确切类型.我使用的ArrayList,所以让我们检查的文档addAll()的List界面:
IllegalArgumentException - 如果指定集合的元素的某些属性阻止将其添加到此列表中
那么,什么元素属性可以阻止元素添加到List?我的两个集合属于同一类型,我应该能够添加空值.
有人可以向我解释一下吗?
我有一个CoordinatorLayout支持FloatingActionButton我想要显示Snackbar..
<android.support.design.widget.CoordinatorLayout
android:id="@+id/rootView"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
...
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_add_field"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/margin_default"
android:layout_marginBottom="@dimen/profile_floating_margin_bottom"
android:layout_marginRight="@dimen/profile_floating_margin_right"
android:clickable="true"
android:src="@drawable/icon_plus"
app:backgroundTint="@color/brand_green"
app:borderWidth="0dp"
app:elevation="@dimen/fac_icon_elevation"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
现在我正在展示Snackbar
Snackbar.make(mRootView, "Something went wrong", Snackbar.LENGHT_SHORT)
.show();
Run Code Online (Sandbox Code Playgroud)
当它显示时,FAB向上滑动,当它(在LENGHT_SHORT之后)消失时,FAB向下滑动,一切正常.
但是,如果我将Snackbar向外滑动,FAB会在没有幻灯片动画的情况下向下移动.它只是闪现到它的初始位置.
有趣的是,如果Snackbar有两条线(无论是否有动作)并被轻扫,FAB会使用通常的幻灯片动画正确地动画回到它的位置.
这是一个bug android.support.design.widget.CoordinatorLayout
还是android.support.design.widget.FloatingActionButton?有什么解决方法吗?
android floating-action-button snackbar android-snackbar android-coordinatorlayout
我明白为什么 Android Studio 显示MissingPermission警告了。
\n\n\n调用需要可能被用户拒绝的权限:代码应显式检查权限是否可用(使用 checkPermission)或显式处理潜在的 SecurityException less... (\xe2\x8c\x98F1)
\n
如果有一个@RequiresPermission注解的方法,需要检查权限。因此,为了防止出现警告,我需要这样做:
if (ActivityCompat.checkSelfPermission(this,\n Manifest.permission.PERMISSION) == PackageManager.PERMISSION_GRANTED) {\n methodThatNeedsAPermission();\n}\nRun Code Online (Sandbox Code Playgroud)\n\n现在,在条件检查中这是一个相当长的代码。此外,我希望我的代码是干净的,我想提取检查以将业务逻辑和 UI / 上下文相关的 Android 代码分开,所以我想要:
\n\npublic void startDoingSomething() {\n if (hasPermission()) {\n methodThatNeedsAPermission();\n }\n}\n\n...\n\npublic boolean hasPermission() {\n return ActivityCompat.checkSelfPermission(this,\n Manifest.permission.PERMISSION) == PackageManager.PERMISSION_GRANTED;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n但这样,Android Studio 仍然显示警告。
\n\n当然,我可以用以下命令抑制警告,@SuppressLint("MissingPermission")但为什么要这样做呢?我正在检查许可。
有没有一种干净的方法来解决这个问题?我会添加某种注释到hasPermission()方法中,以便 Android Studio 知道我正在检查权限?
我想找出以KB为单位的字节数组中保存的图像的大小
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.mPicture);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object
byte[] b = baos.toByteArray();
Run Code Online (Sandbox Code Playgroud)
以下日志显示11.7KB图像的两个不同结果:
Log.d(TAG, "bm size: " + bm.getByteCount()/1024); // 942
Log.d(TAG, "baos size: " + baos.size()/1024); // 81
Log.d(TAG, "byte size: " + b.length/1024); // 81
Run Code Online (Sandbox Code Playgroud)
哪个是正确的结果,或者我如何得到正确的结果?任何帮助表示赞赏.
我正在编写一个针对API级别15的Android应用程序,但我也希望保持与旧API级别(min-sdk 7)的向后兼容性.
我将通过根据当前API级别决定使用哪些代码来实现这一目标(如下所示).我想这是一个好办法,我只想问是否确定有这么多不赞成的方法(像display.getWidth()),因为API级别8和15之间.如果是的话相当多的变化,如果它是一个良好的使用@SuppressWarning("deprecation")在这个案例?
例如,对于API级别<= 8和> = 9,使用多个APK不是更好吗?(尽管developer.android.com不推荐这样做.
Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
Point screenSize = new Point();
// calculate the width
float width;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
display.getSize(screenSize);
width = screenSize.x;
} else {
width = display.getWidth();
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
从今天早上开始,我在所有应用程序构建中都遇到以下错误:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':MyProject:transformClassesWithInstantRunVerifierForQaDebug'.
> tried to access method com.google.common.io.Files.fileTreeTraverser()Lcom/google/common/collect/TreeTraverser; from class com.android.build.gradle.internal.transforms.InstantRunVerifierTransform
* Try:
Run with --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':MyProject:transformClassesWithInstantRunVerifierForQaDebug'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:110)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:77)
at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34) …Run Code Online (Sandbox Code Playgroud) android ×8
java ×2
add ×1
background ×1
deprecated ×1
flutter ×1
google-nexus ×1
kotlin ×1
list ×1
snackbar ×1
spinner ×1
warnings ×1