小编tyn*_*ynn的帖子

EditText lineSpacingExtra奇怪的行为

我有一个EditText,lineSpacingExtra设置为8dp.当我用这个EditText和预设文本打开一个页面时,行间距很好.但是当我在同一页面上点击EditText的末尾并开始输入时,行间距似乎被忽略了.

这是一个错误还是我错过了什么?

在此输入图像描述

添加了代码段.我想,没什么特别的.

<EditText
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        android:padding="8dip"
        android:scrollbars="vertical"
        android:fadingEdge="vertical"
        android:gravity="top"
        android:lineSpacingExtra="8dip"
        android:lineSpacingMultiplier="2"
        android:textSize="18sp"
        android:capitalize="sentences"
        android:inputType="textCapSentences|textMultiLine"
        />
Run Code Online (Sandbox Code Playgroud)

更新:看起来Android 5 Lollipop 附带了这个bug

android line android-edittext android-5.0-lollipop

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

为泛型超类型的类型参数创建TypeToken

我正在TypeAdapter为两个依赖的通用模型实现一个Gson .

interface ModelA<T> {}
interface ModelB<T> extends ModelA<List<T>> {}
Run Code Online (Sandbox Code Playgroud)

为此,我需要得到TypeTokenTypeAdapter.通过做

Type type = ((ParameterizedType) type).getActualTypeArguments()[0];
TypeToken<?> token = TypeToken.get(type);
TypeAdapter<?> adapter = gson.getAdapter(token);
Run Code Online (Sandbox Code Playgroud)

我得到任何给定类型的模型AnyType和相关适配器的类型标记.这是我需要的ModelA,但是因为ModelB我需要使用适配器List<AnyType>,这是ModelA<List<AnyType>>直接使用的结果.

使用原始类型标记的原始类型的接口传递

token.getRawType().getGenericInterfaces()[0]
Run Code Online (Sandbox Code Playgroud)

我似乎只是得到了类型擦除类型List.

如何组合这两个信息以获取泛型List<AnyType>类型或直接创建它?作为输入,它只有类型标记ModelB<AnyType>.

对于给定的行为,我实现了一个显示差异的简单测试.我使用Gson内部非API类expectedhahn的答案中获取了部分内容$Gson$Types.

public class TypeTokenValidate {

    public interface ModelA<T> {}
    public interface ModelB<T> extends ModelA<List<T>> {}

    @Test
    public void genericToken() throws Exception { …
Run Code Online (Sandbox Code Playgroud)

java generics android gson typetoken

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

外部AndroidManifest.xml不会出现在项目视图窗格下

我一直在使用Android Studio和Gradle开发一个Android项目.

我的项目AndroidManifest.xml位于外部文件夹下.我在build.gradle文件中使用以下代码指向它:

sourceSets {
    main {
        manifest.srcFile '..\\..\\..\\sources\\AndroidManifest.xml'
    }
}
Run Code Online (Sandbox Code Playgroud)

一切都很好,项目编译和运行,除了我AndroidManifest.xml在项目视图窗格中找不到项目结构下的文件.

项目结构

也许我需要在build.gradle文件中添加其他内容?

android external gradle android-manifest android-gradle-plugin

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

如何在android中实现共享操作?

我想在我的项目中实现共享操作,但是当我使用MenuItem它时会使用运行时错误MenuItemCompat,但是它也给出了错误.

这是我的代码:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_third_, menu);
    MenuItem menuItem = menu.findItem(R.id.menu_item_share);


    mShareActionProvider = (ShareActionProvider) menuItem.getActionProvider();

    mShareActionProvider.setShareIntent(getDefaultShareIntent());

    return true;
}

public Intent getDefaultShareIntent (){

   Intent shareIntent = new Intent(Intent.ACTION_SEND);

    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, "SUBJECT");
    shareIntent.putExtra(Intent.EXTRA_TEXT,"Extra Text");
    return shareIntent;
}
Run Code Online (Sandbox Code Playgroud)

android

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

将另一个视图作为参数传递给数据绑定

我试图将我的xml的另一个视图作为Google数据绑定中方法的参数传递...像这样:

<LinearLayout
    android:id="@+id/faq_subject_about_ego"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/border_faq_btn"
    android:orientation="horizontal"
    android:layout_marginBottom="20dp"
    android:padding="4dp"
    android:gravity="center"
    android:onClick='@{(faq_title_about) -> viewModel.subjectRequest(faq_title_about.getText())}'>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/icon_faq"
        android:layout_marginRight="8dp"
        android:clickable="false" />

    <ebanx.com.ego.utils.custom_extension.CustomButtonBold
        android:id="@+id/faq_title_about"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/Button_FAQ"
        android:text="@string/btn_about_ego"
        android:clickable="false" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我需要CustomButtonBold中的文本...但这不起作用.

如何将按钮文本作为参数传递?

任何帮助表示赞赏!

java android android-databinding

8
推荐指数
2
解决办法
2588
查看次数

私有内部类的构造函数也是私有的吗?

我正在重构一个正在变大的android项目.运行lint为我提供了JSME问题 外部和内部类之间的私有成员访问.考虑以下示例

public class Outer {
    private Inner mInner = new Inner();

    private class Inner {}
}
Run Code Online (Sandbox Code Playgroud)

我得到了这些信息

Name
   private field Inner mInner

Location
   class Outer (default package)

Problem synopsis
   Access to private member of class 'Inner' at line 2

Problem resolution
   Make 'Inner' constructor package-local
Run Code Online (Sandbox Code Playgroud)

应用问题解决方案会将源更改为

public class Outer {
    private Inner mInner = new Inner();

    private class Inner {
        Inner() {}
    }
}
Run Code Online (Sandbox Code Playgroud)

我此刻有点困惑.到现在为止,我认为这个例子相当于

public class Outer {
    private Inner mInner = new Inner();

    private class …
Run Code Online (Sandbox Code Playgroud)

java android inner-classes android-lint android-studio

7
推荐指数
1
解决办法
1167
查看次数

Kotlin 中如何检查变量是否为数组

我的科特林代码是

val t = cameraController.getCharacteristicInfo(myDataset[position])
if (t is Array<*>) {
     holder.keyValue.text = Arrays.toString(t)
} else {
     holder.keyValue.text = t.toString()
}
Run Code Online (Sandbox Code Playgroud)

不起作用if (t is Array<*>)总是会回来false

该函数的代码getCharacteristicInfo为:

public <T> T getCharacteristicInfo(CameraCharacteristics.Key<T> key) {
    return characteristics.get(key);
}
Run Code Online (Sandbox Code Playgroud)

它是获取相机特性的函数。

如何正确检查变量是否是数组?

android kotlin

7
推荐指数
1
解决办法
5923
查看次数

RoomProcessor编译或循环依赖

我一直在努力解决Android Room组件的问题,

我所做的就是将我的Android Studio从3.3升级到3.4.1,同时完成了gradle等更改。我什至尝试回到3.3,但没有任何效果。我一直Run with --info or --debug option在尝试查看更多详细信息,但没有任何信息可以为我提供更多信息。请帮忙

e: /.../app/build/tmp/kapt3/stubs/debug/com/.../model/HotspotEntity.java:7: error: [RoomProcessor:MiscError] androidx.room.RoomProcessor was unable to process this class because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code.
public final class HotspotEntity implements android.os.Parcelable {
             ^
e: /.../app/build/tmp/kapt3/stubs/debug/com/.../ConditionEntity.java:7: error: [RoomProcessor:MiscError] androidx.room.RoomProcessor "same as above".
public final class ConditionEntity implements android.os.Parcelable {
             ^
e: /.../app/build/tmp/kapt3/stubs/debug/com/.../model/AdLimits.java:6: error: [RoomProcessor:MiscError] androidx.room.RoomProcessor "same as above"
public final class AdLimits {
             ^ …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-room

7
推荐指数
1
解决办法
672
查看次数

GitHub OAuth 注销或撤销令牌

要使用GitHub应用程序对用户进行身份验证,我们只需要向loginapi发出两个请求:

GET https://github.com/login/oauth/authorize
POST https://github.com/login/oauth/access_token
Run Code Online (Sandbox Code Playgroud)

现在我们已经使用了token,我们如何撤销它以注销用户?

javascript oauth github logout github-api

7
推荐指数
0
解决办法
278
查看次数

无法访问活动绑定android

我有一个名为activity_suggestions. 我在其中使用数据绑定。因此文件ActivitySuggestionsBinding被生成。项目编译成功。但是当我尝试运行该项目时,出现此错误

e: error: cannot access ActivitySuggestionsBinding
Run Code Online (Sandbox Code Playgroud)

我正在使用3.1.2带有 kotlin 版本的android studio 1.4.1。任何帮助将不胜感激

编辑
粘贴我的模块级别 build.gradle 和应用级别 build.gradle

模块 Build.gradle

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {

    dataBinding {
        enabled = true
    }
..
}

dependencies{
..
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation "com.google.dagger:dagger:$rootProject.daggerVersion"
    implementation "com.google.dagger:dagger-android:$rootProject.daggerVersion"
    implementation "com.google.dagger:dagger-android-support:$rootProject.daggerVersion"
    kapt "com.google.dagger:dagger-android-processor:$rootProject.daggerVersion"
    kapt "com.google.dagger:dagger-compiler:$rootProject.daggerVersion"
    provided 'javax.annotation:jsr250-api:1.0'
    implementation "android.arch.lifecycle:runtime:$rootProject.archVersion"
    implementation "android.arch.lifecycle:extensions:$rootProject.archVersion"
    annotationProcessor "android.arch.lifecycle:compiler:$rootProject.archVersion"
    kapt "com.android.databinding:compiler:3.1.2"
..
}
Run Code Online (Sandbox Code Playgroud)

应用程序构建.gradle

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android{

    dataBinding{
        enabled = true …
Run Code Online (Sandbox Code Playgroud)

data-binding android kotlin android-databinding android-studio-3.0

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