小编Axb*_*rov的帖子

使用消息进行索引冻结:由于批量更新而导致索引暂停

我已将Android Studio更新到3.2版.

在更新之后,我的一个项目不想索引.

它冻结了消息

"由于批量更新,索引暂停".

我怎样才能解决这个问题?

Gradle包装器属性:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
Run Code Online (Sandbox Code Playgroud)

Gradle属性

org.gradle.jvmargs=-Xmx1536m
org.gradle.parallel=true
org.gradle.daemon=true
org.gradle.configureondemand=true
Run Code Online (Sandbox Code Playgroud)

android-studio android-gradle-plugin

138
推荐指数
11
解决办法
3万
查看次数

Right shift operator for byte in kotlin

I have next code in java:

private final static char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
public static String bytesToHex(byte[] bytes) {
    char[] hexChars = new char[bytes.length * 2];
    for (int j = 0; j < bytes.length; j++) {
    int v = bytes[j] & 0xFF;
        hexChars[j * 2] = HEX_ARRAY[v >>> 4];
        hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
    }

    return new String(hexChars);
}
Run Code Online (Sandbox Code Playgroud)

I want to convert this code to kotlin. Autoconverting gave next result:

fun bytesToHex(bytes: ByteArray): String { …
Run Code Online (Sandbox Code Playgroud)

java kotlin

6
推荐指数
1
解决办法
5280
查看次数

LazyColumn StickyFooter 或将焦点放在底部项目上

我想创建一个小信使,其中的消息从底部添加(新消息放置在列表的底部)。为了实现这一点,我将LazyColumnsreversedLayout属性设置为true。但如果我这样做,粘性标题也会被反转(就像粘性页脚一样)。如果我将属性设置verticalArrangement为, Bottom那么当键盘打开时,下面的消息不会保持焦点(它将转到下面的键盘)。此外,消息列表不是从最新的消息开始,而是从最旧的消息开始(就像从顶部开始滚动一样)。

StickyFooter 或将焦点保持在底部项目可以解决问题吗?我能为此做什么?

我写的代码:

LazyColumn(
    modifier = Modifier
        .fillMaxWidth()
        .weight(1f),
    contentPadding = PaddingValues(horizontal = 16.dp, vertical = 8.dp),
    reverseLayout = true,
) {
    val messages = state.messages.asReversed()
    messages.forEachIndexed { index, message ->
        val nextMessage = messages.getOrNull(index - 1)
        val prevMessage = messages.getOrNull(index + 1)
        val isNearToPrevious = isNear(message, prevMessage)
        val isNearToNext = isNear(message, nextMessage)
        item(message.id) {
            GroupMessageItem(
                message,
                isNearToPrevious,
                isNearToNext
            )
        }
        if (!message.createdAt.isSameDayWith(prevMessage?.createdAt)) {
            stickyHeader(key = "item: ${message.id}") { …
Run Code Online (Sandbox Code Playgroud)

android-jetpack-compose lazycolumn

6
推荐指数
0
解决办法
541
查看次数

找不到符号变量FLAG_ACTIVITY_CLEAR_TASK

更新支持版本到27.0.0编译器给出错误

cannot find symbol variable FLAG_ACTIVITY_CLEAR_TASK.

这个变量被删除了吗?有什么用呢?

代码示例:

 Intent intent = new Intent(SetNewPasswordActivity.this, SignInActivity.class);
 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);
Run Code Online (Sandbox Code Playgroud)

android

5
推荐指数
1
解决办法
2171
查看次数

使用新的 androidx.BiometricPrompt 通过生物识别注册使密钥无效

我正在使用新androidx.BiometricPromt库通过指纹实现身份验证。如果用户添加新指纹或删除指纹,我想使密钥无效。我正在创建这样的密钥:

fun getSecretKey(shouldCreate: Boolean): Key {
    val keyStore = KeyStore.getInstance(ANDROID_KEYSTORE)
    keyStore.load(null)
    return if (shouldCreate) {
        createSecretKey(keyStore)
    } else {
        keyStore.getKey(ALIAS_BIOMETRICS, null)
    }
}

private fun createSecretKey(keystore: KeyStore): Key {
    val builder = KeyGenParameterSpec.Builder(
        ALIAS_BIOMETRICS,
        KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT
    )
        .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
        .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
        .setUserAuthenticationRequired(true)
        .setUserAuthenticationValidityDurationSeconds(5)

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        builder.setInvalidatedByBiometricEnrollment(true)
        builder.setUserAuthenticationValidWhileOnBody(true)
    }

    val keyGenerator =
        KeyGenerator.getInstance(keyAlgorithm, keystore.provider)
    keyGenerator
        .init(builder.build())
    return keyGenerator.generateKey()
}
Run Code Online (Sandbox Code Playgroud)

我正在开始这样的生物识别扫描过程:

val info = BiometricPrompt.PromptInfo.Builder()
    .setTitle(context.getString(R.string.biometric_dialog_title))
    .setSubtitle(context.getString(R.string.biometric_dialog_subtitle))
    .setNegativeButtonText(context.getString(R.string.biometric_dialog_cancel))
    .build()

biometricPrompt = when (screen) {
    is FragmentActivity -> BiometricPrompt(screen, …
Run Code Online (Sandbox Code Playgroud)

android android-keystore android-biometric-prompt

5
推荐指数
0
解决办法
250
查看次数

编程端ActionBar中可绘制的后退箭头ID

我正在寻找后退箭头的默认可绘制对象。在这个问题中展示了如何在 xml 中获取它。但我正在寻找在编程方面使用(java/kotlin)。

我想在如下代码中使用这个 drawable id:

ContextCompat.getDrawable(context, homeAsUpIndicatorId);
Run Code Online (Sandbox Code Playgroud)

java android kotlin android-resources

3
推荐指数
1
解决办法
1109
查看次数

Android ViewPager像instagram照片活动

我需要对“照片和视频”选项卡使用相同的片段,但仍然有三个选项卡。我在viewpager中有两个片段,在tablayout中有3个选项卡。我想实现像instagram这样的viewpager更改效果。我所做的:我在下面创建了自定义viewpager:

public class SwipableViewPager extends ViewPager {
    private float downX;
    private float downY;
    private float mStartDragX;
    private float upX;
    private float upY;
    private boolean dragDisabled;

    private SwipeListener mListener;

    public void setSwipeListener(SwipeListener listener) {
        mListener = listener;
    }

    public SwipableViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        float x = ev.getX();
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                downX = ev.getX();
                downY = ev.getY();
                mStartDragX = x;
                break;
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP:
                upX = ev.getX();
                upY = …
Run Code Online (Sandbox Code Playgroud)

android android-viewpager

2
推荐指数
1
解决办法
1466
查看次数

fontFamily 属性无法通过 textAppearance 工作

我有下一个风格:

 <style name="Text.Light">
        <item name="android:fontFamily">@font/open_sans_light</item>
    </style>
Run Code Online (Sandbox Code Playgroud)

如果我在设计时TextView通过textAppearancelike将它设置为in xml ,android:textAppearance="@style/Text.Italic"它会显示斜体字体,但在运行时它不会影响。但是,如果直接在 TextView 中使用 fontFamily 就像android:fontFamily="@font/open_sans_italic"它在两种情况下(设计和运行时)都完美无缺。我究竟做错了什么?有我的字体系列 xml:

<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:ignore="UnusedAttribute">

    <font
        android:font="@font/open_sans_regular"
        android:fontStyle="normal"
        android:fontWeight="400"
        app:font="@font/open_sans_regular"
        app:fontStyle="normal"
        app:fontWeight="400" />

    <font
        android:font="@font/open_sans_italic"
        android:fontStyle="italic"
        android:fontWeight="400"
        app:font="@font/open_sans_italic"
        app:fontStyle="italic"
        app:fontWeight="400" />
</font-family>
Run Code Online (Sandbox Code Playgroud)

android android-layout android-fonts android-studio

2
推荐指数
1
解决办法
1794
查看次数