我正在阅读关于Android的房间库.我看到他们改变包装android来androidx.我不明白.请有人解释一下.
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
Run Code Online (Sandbox Code Playgroud)
即使这也适用于android包装.
implementation "android.arch.persistence.room:runtime:$room_version"
annotationProcessor "android.arch.persistence.room:compiler:$room_version"
Run Code Online (Sandbox Code Playgroud)
androidx而不是android.android android-architecture-components android-jetpack androidx
我试图用新的Android P FloatingActionButton这部分com.google.android.material.floatingactionbutton.FloatingActionButton和我得到这样的警告:
VisibilityAwareImageButton.setVisibility只能从同一个库组中调用(groupId = com.google.android.material)
import com.google.android.material.floatingactionbutton.FloatingActionButton
import android.view.View
class MainActivity : AppCompatActivity() {
lateinit var demoFab: FloatingActionButton
override fun onCreate(savedInstanceState: Bundle?) {
demoFab = findViewById(R.id.demoFab)
demoFab.visibility = View.VISIBLE // the warning is here
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试过搜索,唯一的搜索结果是关于响应UI可见性更改:
https://developer.android.com/training/system-ui/visibility
我试着探索如何VISIBLE在该com.google.android.material包中找到一个int值,并且我找到的唯一一个是com.google.android.material.floatingactionbutton.FloatingActionButton.VISIBLE,但警告仍然存在.
buildscript {
ext.kotlin_version = '1.2.41'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-alpha14'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.gms:oss-licenses:0.9.2"
// NOTE: Do not place your application dependencies here; they belong
// in …Run Code Online (Sandbox Code Playgroud) 自 Jetpack 发布以来,我们一直在使用DataBinding。Android 文档表明ViewBinding已添加到Android Studio 3.6 Canary 11+ 中。
我阅读了文档,但它看起来类似于DataBinding。
谁能解释一下这两个概念之间的区别?
data-binding android android-databinding android-jetpack android-viewbinding
我正在尝试使用 jetpack compose 中的 observeAsState 从 LiveData 获取值,但我收到一个奇怪的错误
类型 'State<List?>' 没有方法 'getValue(Nothing?, KProperty<*>)',因此它不能作为委托
@Composable
fun UserScreen(userViewModel:UserViewModel){
val items: List<User> by userViewModel.fetchUserList.observeAsState()
UserList(userList = items)
}
Run Code Online (Sandbox Code Playgroud)
class UserViewModel: ViewModel() {
private val dataSource = UserDataSource()
val fetchUserList = liveData {
emit(dataSource.dummyUserList)
}
}
Run Code Online (Sandbox Code Playgroud) 我知道,androidx和支持依赖导致multidex错误 我们不能同时使用androidx和android支持.所以我完全迁移到androidx.但我的一个依赖lib使用了android支持"lottie".
在上述情况下我们能做些什么?我应该从我的项目中删除'lottie'吗?
下面是我的傻瓜
defaultConfig {
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
}
ext{
lottieVersion = "2.5.4"
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
def androidx = "1.0.0-rc01"
api "androidx.constraintlayout:constraintlayout:1.1.2"
api "androidx.appcompat:appcompat:$androidx"
api "androidx.recyclerview:recyclerview:$androidx"
api "androidx.cardview:cardview:$androidx"
api "androidx.core:core-ktx:$androidx"
api "com.google.android.material:material:1.0.0-rc01"
implementation "com.google.code.gson:gson:2.8.5"
implementation "androidx.multidex:multidex:2.0.0"
implementation "com.airbnb.android:lottie:$lottieVersion"
}
Run Code Online (Sandbox Code Playgroud) 我正在搜索如何在 Jetpack Compose 中创建自定义对话框。在 XML 或 Material Design 中,我们可以轻松创建自定义对话框,在其中我们可以接受用户输入、单选按钮等,但我在 Jetpack Compose 中没有找到这样的东西。
android android-alertdialog android-jetpack android-jetpack-compose android-compose-dialog
我在 jetpack compose 中创建了简单的卡片,在这里我设置了海拔,但它显示类型不匹配。
Card(
shape = RoundedCornerShape(20.dp),elevation = 10.dp
) {
Box(modifier = Modifier.height(200.dp)) {
Image(painter = painter, contentDescription = contentDescription,
contentScale = ContentScale.Crop)
}
}
Run Code Online (Sandbox Code Playgroud)
android android-cardview android-jetpack android-jetpack-compose android-compose-card
在尝试导航组件之前,我曾经手动执行片段事务并使用片段标记来获取当前片段.
val fragment:MyFragment = supportFragmentManager.findFragmentByTag(tag):MyFragment
现在在我的主要活动布局中,我有类似的东西:
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/nav_host"
app:navGraph= "@navigation/nav_item"
android:name="androidx.navigation.fragment.NavHostFragment"
app:defaultNavHost= "true"
/>
Run Code Online (Sandbox Code Playgroud)
如何通过导航组件检索当前显示的片段?干
supportFragmentManager.findFragmentById(R.id.nav_host)
返回一个NavHostFragment,我想检索我显示的'MyFragment`.
谢谢.
fun createListItem(itemIndex: Int) {
Padding(left = 8.dp, right = 8.dp, top = 8.dp, bottom = 8.dp) {
FlexRow(crossAxisAlignment = CrossAxisAlignment.Center) {
expanded(1.0f) {
Text("Item $itemIndex")
}
inflexible {
Button(
"Button $itemIndex",
style = ContainedButtonStyle(),
onClick = {
Toast.makeText(
this@MainActivity,
"Item name $itemIndex",
Toast.LENGTH_SHORT
).show()
})
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试以正常方式制作 Toast。但我得到了错误我尝试了很多倍数来源但失败了。
我已经看过Google I/O 2018的开发人员主题演讲,我已经在Android开发者网站上阅读了jetpack主页,但我无法理解它实际上是什么.对我来说,它似乎只是我们已经使用的一堆API的新名称.是否会有IDE为我们做的事情或者在编码时有用的东西?Jetpack中的所有组件都指向他们原来的Android文档,并没有实际显示出与以前相比的任何差异.有人可以用简单的术语解释Jetpack实际上对我作为开发人员的作用,除了网页上的俱乐部文档吗?
android ×10
android-jetpack ×10
kotlin ×3
android-architecture-components ×1
androidx ×1
data-binding ×1