拥有更新的Android Studio 3.0非常棒.但是我遇到了Android Studio 3.0的问题,我刚刚在Android Studio 3.0中创建了一个新项目.然后我收到了一些错误
我通过更改dependencies到最新版本解决了这些问题并解决了问题.
但是,当我加了dependency的Facebook帐户,包SDK com.facebook.android:account-kit-sdk:4.+
我得到以下错误 - :
错误:无法解析':app @ debug/compileClasspath'的依赖项:无法解析com.facebook.android:account-kit-sdk:4.+.打开文件
显示细节
的build.gradle(APP)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 26
defaultConfig {
applicationId "ultimate.devil.logintest"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation …Run Code Online (Sandbox Code Playgroud) 我正在学习Kotlin.在此之前,我曾使用Java进行Android开发.Kotlin是一门很好的学习语言.我在使用时感到困惑setOnClickListener(View.OnClickListener).我在Android Studio上看到了两个提示.
我知道如何工作或定义它们.
第一种实施方式 OnClickListerner
send_button.setOnClickListener(object : View.OnClickListener{
override fun onClick(p0: View?) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
})
Run Code Online (Sandbox Code Playgroud)
这是第二种实施方式 OnClickListener
send_button.setOnClickListener {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
Run Code Online (Sandbox Code Playgroud)
我理解第二种方法基于lambda.但我无法正确理解这些方法.
所以,我的问题是:这些方法有什么区别?如果它们不同,哪一个更好,为什么?
我有一个RecyclerView。在其适配器内部onBindViewHolder(),将OnClickListener设置为ViewHolder的根布局。
但是,我最近注意到,RecyclerView在滚动时无法点击的项目。只有在它停止之后。如果RecyclerView在滚动时单击某处,则RecyclerView仅在该位置停止,不会单击任何项目。
您可以在Gmail应用程序中了解我的意思。滚动电子邮件时,您无法打开任何电子邮件RecyclerView。
但是,Google Play应用的行为有所不同。您可以在滚动应用程序列表的同时打开应用程序页面。您甚至可以在滚动RecyclerView父级时水平滚动inner RecyclerView。
我也注意到ScrollView的行为相同。例如,如果您在其中放置了很多按钮并开始滚动,则不会触发按钮侦听器。只有在ScrollView完全停止后才能触发它们。
您是否知道如何实现类似Google Play应用中的行为?谢谢!
我试图在我的手机上运行我的应用程序,但在build时间失败时出现以下错误:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
Run Code Online (Sandbox Code Playgroud)
java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
到目前为止我尝试过但无济于事: - >清理并重建(重建失败) - >删除./gradle文件和所有项目构建和缓存文件,然后缓存失效
我的项目gradle文件:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.1.51'
repositories {
jcenter()
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta6'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
jcenter()
google() …Run Code Online (Sandbox Code Playgroud) 我有Java代码,Service并试图将其转换为Kotlin.
class MyService : Service() {
companion object MyBinder : Binder() {
fun getService() : MyService? {
return MyService::class.objectInstance
}
}
// service implementation
}
Run Code Online (Sandbox Code Playgroud)
问题是在活动中getService()始终返回null.我确定它service是在之前启动的,我在logcat中看到它.我建议这个来自Java代码的自动生成的行应该是不同的但我找不到解决方案:
return MyService::class.objectInstance
Run Code Online (Sandbox Code Playgroud)
在Java代码中它是:
return MyService.this
Run Code Online (Sandbox Code Playgroud) 下面是我的代码。
holder.followDiseaseCheckBox.setOnClickListener(new View.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onClick(View view) {
if (holder.followDiseaseCheckBox.isChecked()) {
holder.followDiseaseCheckBox.setChecked(true);
checkBoxClicked++;
holder.followDiseaseCheckBox.setChecked(true);
// for Follow.
if (isFollowOrUnFollow.equals("FOLLOW")) {
((FollowActivity) context).diseaseListFromAdapter.add(String.valueOf(diseaseMap.get("id")));
((FollowActivity) context).setFollowButton(true);
}
// for Unfollow.
else if (isFollowOrUnFollow.equals("UN_FOLLOW")) {
((FollowTwoActivity) context).unFollowedDiseaseListFromAdapter.add(String.valueOf(diseaseMap.get("id")));
((FollowTwoActivity) context).setUnFollowDiseaseButton(true);
}
} else {
holder.followDiseaseCheckBox.setChecked(false);
checkBoxClicked--;
holder.followDiseaseCheckBox.setChecked(false);
// for Follow.
if (isFollowOrUnFollow.equals("FOLLOW")) {
((FollowActivity) context).diseaseListFromAdapter.remove(String.valueOf(diseaseMap.get("id")));
}
// for Unfollow.
else if (isFollowOrUnFollow.equals("UN_FOLLOW")) {
((FollowTwoActivity) context).unFollowedDiseaseListFromAdapter.remove(String.valueOf(diseaseMap.get("id")));
}
if (checkBoxClicked == 0) {
// for Follow.
if (isFollowOrUnFollow.equals("FOLLOW")) {
((FollowActivity) context).setFollowButton(false); …Run Code Online (Sandbox Code Playgroud) 可能重复但没有找到任何解决方案。
我正在尝试修改图像并将其保存到设备使用MediaStore. 使用以下代码 -:
public class Utils {
private Utils() {
}
static Uri getUri(Context context, Bitmap bitmap) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, "Title", null); //returning null in some devices
Log.d("TAG", "getUri: "+path);
return Uri.parse(path); //this is returning null which cause the app crash
}
static Bitmap getBitmap(Context context, Uri uri) throws IOException {
return MediaStore.Images.Media.getBitmap(context.getContentResolver(), uri);
}
}
Run Code Online (Sandbox Code Playgroud)
此代码在大多数设备中运行良好,但问题是MediaStore.Images.Media.insertImage在某些设备中返回 null,例如 -:
1 . 三星J7(2016)
2 . …
我正在尝试聊天。MainActivity有一个ToolBar和BottomNavigationVIew。
聊天fragment有一个recyclerView,一个editText和ImageButton,但是当我加载片段时BottomNavigationVIew,EditText和重叠ImageButton
我不知道这是否重要,但在 Android Studio 中,该项目BottomNavigationVIew看起来比实际小,例如不像 ToolBar 也是我使用的android:layout_above="@+id/navigation",但它不起作用

我尝试了很多方法,但我做不到
活动_main.xml
<RelativeLayout 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:id="@+id/activity_home"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_parent_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="@string/parent_name"
android:textSize="20sp" />
<de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/student_photo"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="right|center"
android:onClick="onClick"
android:padding="4dp"
android:src="@drawable/foto"
app:civ_border_color="@color/iron"
app:civ_border_width="1dp" /> …Run Code Online (Sandbox Code Playgroud)