小编Zai*_*ain的帖子

未解决的参考:升级生命周期依赖项后的转换

将生命周期依赖项从 升级到 后,2.6.0-alpha042.6.0-beta01得到了未解决的参考:转换并且它无法import androidx.lifecycle.Transformations分类。

import androidx.lifecycle.Transformations
...
var myList: LiveData<List<Bookmark>> = Transformations.switchMap(
            bookMarkType
        ) { input: Int? ->
            when (input) {
                ARTICLE_BOOKMARK -> return@switchMap repository.articleBookmarks
                WEBSITE_BOOKMARK -> return@switchMap repository.websiteBookmarks
                LINK_BOOKMARK -> return@switchMap repository.linkBookmarks
            }
            repository.websiteBookmarks
        }
Run Code Online (Sandbox Code Playgroud)

android android-livedata android-livedata-transformations

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

Android Studio 登录Github失败

我想在 Github 上分享我的 Android Studio 项目,但是当我点击分享时,它似乎

http://127.0.0.1:63342/api/github/oauth/authorization_code?code=14c943d3435fe66a54f7

它要求输入用户名和密码。我尝试使用我的 Github 用户名和密码登录但失败。

*刚刚开始编程2周

android github android-studio

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

BottomSheet + ViewPager2 拖动隐藏不起作用

我遇到了麻烦,我认为是我CoordinatorLayout的错,但不确定。我ViewPager2在 a 内部使用ConstraintLayout,我使用CoordinatorLayoutlike BottomSheet。但是当我拖动以隐藏它时效果不佳。我替换了ViewPager2byViewPager并且效果很好。我希望你能帮助我。

这是我的 XML 文件:

    <androidx.coordinatorlayout.widget.CoordinatorLayout 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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/bottom_sheet_behavior"
        app:behavior_hideable="false"
        app:behavior_peekHeight="60dp" >

        <androidx.viewpager2.widget.ViewPager2
            android:layout_width="match_parent"
            android:layout_height="0dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintDimensionRatio="4:3"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:background="#0000FF"/>
    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

android android-coordinatorlayout bottom-sheet android-viewpager2

13
推荐指数
1
解决办法
541
查看次数

发现问题:缺少对数据安全表的独立安全审查

我们发现以下领域存在问题:

\n

策略声明\xe2\x80\x94数据安全部分

\n

图像

\n

android google-play

10
推荐指数
1
解决办法
6203
查看次数

如何添加 recyclerview 项目删除动画

当我使用它时,它会删除一个带有动画的元素

{
    notificationItems.remove(0);
    adapterForNotification.notifyItemRemoved(0);                        
    adapterForNotification.notifyItemRangeRemoved(0,count-1);
}
Run Code Online (Sandbox Code Playgroud)

但是,当我使用它时,它会删除所有没有动画的元素

count = adapter.getItemCount();
for(int i = 0 ; i < count; ++i){
    notificationItems.remove(0);
    adapterForNotification.notifyItemRemoved(0);
    adapterForNotification.notifyItemRangeRemoved(0,count-1)
}
Run Code Online (Sandbox Code Playgroud)

android removeall android-animation android-recyclerview

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

发现多个文件与操作系统无关的路径“mockito-extensions/org.mockito.plugins.MockMaker”

发现多个文件与操作系统无关的路径'mockito-extensions/org.mockito.plugins.MockMaker'在添加时出现此错误 androidTestImplementation "org.mockito:mockito-inline:2.15.0"

在 gradle 中模拟最后一堂课

android mockito kotlin android-testing

8
推荐指数
1
解决办法
2901
查看次数

是否可以使用微调器实现暴露的下拉菜单

Material design 有一个 Exposed Dropdown Menu,实现AutoCompleteTextView如下:

<com.google.android.material.textfield.TextInputLayout
    style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/hint_text">

  <AutoCompleteTextView
      android:id="@+id/filled_exposed_dropdown"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"/>

</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)

但是我需要具有相同的外观和感觉,但具有微调器行为(没有自动完成功能,只需显示弹出窗口并选择一个项目)。

我禁用了对 AutoCompleteTextView 的编辑以避免使用自动完成功能,但是在选择其中一个项目后,自动完成功能只列出与给定此视图中使用的过滤器选择的项目文本匹配的项目。这是代码:

    <AutoCompleteTextView
            android:id="@+id/filled_exposed_dropdown"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="16dp"
            **android:editable="false"**/>
Run Code Online (Sandbox Code Playgroud)

当点击它时,我还放了一个监听器来打开项目列表

val editTextFilledExposedDropdown = findViewById<AutoCompleteTextView>(R.id.filled_exposed_dropdown)
    editTextFilledExposedDropdown.setAdapter(adapter)
    editTextFilledExposedDropdown.setOnClickListener {
        (it as AutoCompleteTextView).showDropDown()
}
Run Code Online (Sandbox Code Playgroud)

所以,我想知道是否可以使用微调器来实现这一点

在此处输入图片说明

这是我使用微调器的尝试,但它没有正确显示样式OutlinedBox.Dense.ExposedDropdownMenu并且还显示两个箭头底部图标,我认为一个用于样式,另一个用于微调器。

这是带有微调器的代码:

<com.google.android.material.textfield.TextInputLayout
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Hint">
    <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

</com.google.android.material.textfield.TextInputLayout>


<com.google.android.material.textfield.TextInputLayout
        android:id="@+id/layout_id"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Currency">
    <androidx.appcompat.widget.AppCompatSpinner
            android:id="@+id/my_spinner"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)

android autocompletetextview android-view material-design

8
推荐指数
1
解决办法
1万
查看次数

如何使用 Android 导航组件在某些片段中隐藏操作栏?

我正在使用 android 导航组件来导航片段。我可以通过在 Main Activity 中使用此代码轻松设置操作栏:

    NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
    NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
Run Code Online (Sandbox Code Playgroud)

但是如果我想在某些片段中隐藏 supportActionbar 那么最好的方法是什么?

java android android-fragments android-navigation android-architecture-navigation

8
推荐指数
1
解决办法
2564
查看次数

如何使用导航组件管理权限请求代码?

如何使用导航组件管理权限请求代码?

我引用了太多网站和堆栈链接,但没有一个起作用,仍然显示已弃用的 Waring 在此输入图像描述

谷歌参考链接: https://developer.android.com/training/permissions/requesting#manage-request-code-yourself

代码::在片段中使用以下代码

  private fun checkMultiplePermissions() {
        // check permission first
        if (ActivityCompat.checkSelfPermission(requireContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            // request the permission
            requestPermissions(arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), 100)
        } else {
            proceedAfterPermission()  // has the permission.
        }
    }
    override fun onRequestPermissionsResult(requestCode: Int,
                                            permissions: Array<String>, grantResults: IntArray) {
        myLog("log", "location code : $requestCode")
        when (requestCode) {
            100 -> {
                // If request is cancelled, the result arrays are empty.
                if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    // permission was granted.
                    proceedAfterPermission() // …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-permissions android-architecture-components registerforactivityresult

8
推荐指数
1
解决办法
1万
查看次数

如何以编程方式重新启动Android应用程序

我想通过待处理意图重新启动我的应用程序。下面的代码不起作用。

val intent = Intent(this, Activity::class.java).apply {
     flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
}
val pendingIntentId = 1
val pendingIntent = PendingIntent.getActivity(this, pendingIntentId, intent, PendingIntent.FLAG_CANCEL_CURRENT)
val mgr = getSystemService(Context.ALARM_SERVICE) as AlarmManager
val timeToStart = System.currentTimeMillis() + 1000L
mgr.set(AlarmManager.RTC, timeToStart, pendingIntent)
exitProcess(0)
Run Code Online (Sandbox Code Playgroud)

目标版本是 31,因此更新了未决意图,但PendingIntent.FLAG_MUTABLE仍然不起作用。我搜索了许多与此相关的链接,但没有运气。

以编程方式重新启动 Android 应用程序

强制应用程序在第一个活动时重新启动

https://www.folkstalk.com/tech/restart-application-programmatically-android-with-code-examples/#:~:text=How%20do%20I%20programmatically%20restart,finishes%20and%20automatically%20relaunches% 20us.%20%7D

2022 年 11 月,当目标版本为 31 且最低 sdk 版本为 29 时,上述待处理意图代码不会重新启动应用程序。

除了重新启动活动之外,还有为什么上述未决意图不起作用的任何线索或任何其他建议吗?我不想使用重新启动startActivity(intent)

android alarmmanager android-pendingintent

8
推荐指数
1
解决办法
3714
查看次数