相关疑难解决方法(0)

Android:在Button或ImageButton上组合文本和图像

我正在尝试在按钮上创建一个图像(作为背景)并动态添加,具体取决于运行时发生的情况,图像上方/上方的一些文本.

如果我使用ImageButton我甚至没有可能添加文本.如果我使用,Button我可以添加文本,但只定义具有此处android:drawableBottom定义的XML属性的图像.

然而,这些属性仅在x和y维度中组合文本和图像,这意味着我可以在文本周围绘制图像,但不能在我的文本下方/下方(z轴定义为从显示中出来).

有关如何做到这一点的任何建议?一个想法是扩展ButtonImageButton覆盖draw()-method.但凭借我目前的知识水平,我真的不知道如何做到这一点(2D渲染).也许有经验的人知道解决方案或至少有一些指针可以开始?

android text image button

526
推荐指数
14
解决办法
53万
查看次数

有没有办法在Android Studio编辑器中显示RecyclerView内容的预览?

当我将RecyclerView添加到布局时,它显示为空白屏幕.有没有办法,比如通过tools名称空间,来显示RecyclerView内容的预览?

android android-studio android-recyclerview android-tools-namespace

270
推荐指数
3
解决办法
7万
查看次数

Android Material和appcompat Manifest合并失败

我有下一个年级

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.android.material:material:1.0.0-rc01'
}
Run Code Online (Sandbox Code Playgroud)

但是当我想构建应用程序时,我会得到下一个日志:

Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0-alpha3] AndroidManifest.xml:22:18-91
    is also present at [androidx.core:core:1.0.0-alpha3] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
    Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-19:19 to override.
Run Code Online (Sandbox Code Playgroud)

好! 去清单并执行:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="ru.chopcode.myapplication">

    <application
        tools:replace="android:appComponentFactory"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
    </application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

然后我在Logcat中收到此错误:

Manifest merger failed with multiple errors, see logs that I have …
Run Code Online (Sandbox Code Playgroud)

android build.gradle android-gradle-plugin gradle-plugin

193
推荐指数
19
解决办法
29万
查看次数

错误:程序类型已存在:android.support.design.widget.CoordinatorLayout $ Behavior

我在构建项目时遇到以下错误.在这个项目中没有使用CoordinatorLayout.刚刚在build.gradle中添加为依赖项:

我使用的是Android Studio 3.2 Canary 4.

logcat的

AGPBI:{"kind":"error","text":"程序类型已存在:android.support.design.widget.CoordinatorLayout $ Behavior","sources":[{}],"tool":"D8" }:app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED FAILURE:构建因异常而失败.*出了什么问题:任务执行失败':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

com.android.builder.dexing.DexArchiveMergerException:合并dex存档时出错:/windows/Other/app/build/intermediates/transforms/dexBuilder/debug/0.jar,/ windows/Other/app/build/intermediates/transforms/dexBuilder/debug/1.jar,/windows/Other/app/build/intermediates/transforms/dexBuilder/debug/4.jar,.....................

/windows/Other/app/build/intermediates/transforms/dexBuilder/debug/294.jar

程序类型已存在:android.support.design.widget.CoordinatorLayout $ Behavior

的build.gradle

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

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

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"
    defaultConfig {
        applicationId "com.dagkot"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField "String", "BASE_URL", "\"http://api.openweathermap.org/data/2.5/\""
            buildConfigField "String", "API_KEY", "\"435e9075f348868c2714fe7c6895efa5\""
        }
        debug {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        buildConfigField "String", …
Run Code Online (Sandbox Code Playgroud)

android kotlin dagger-2 android-coordinatorlayout

127
推荐指数
9
解决办法
17万
查看次数

将支持库添加到Android Studio项目

我刚刚安装了新的Android Studio,我正在寻找一种方法来导入Android的支持库.

那个选项在哪里?在Eclipse中只需两次点击.我用谷歌搜索但没有发现任何东西.当然它太新了.

android android-support-library android-studio

110
推荐指数
5
解决办法
11万
查看次数

API 28(P)的Android设计支持库无法正常工作

我已经成功配置了android-P SDK环境.当我尝试使用android设计支持库时,我面临项目构建错误.项目配置是:

IDE:3.2 Canary 17目标API:28编译API:28

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.app.navigationpoc"
        minSdkVersion 21
        targetSdkVersion 28
        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(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.1'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'

    implementation 'com.android.support:design:28.0.0-alpha3'
    implementation 'com.android.support:cardview-v7:28.0.0-alpha3'
}
Run Code Online (Sandbox Code Playgroud)

并且构建失败的错误是:

清单合并失败:来自[androidx.core:core:1.0.0-alpha3] AndroidManifest.xml:22:18-86的属性应用程序@ appComponentFactory值=(androidx.core.app.CoreComponentFactory)也出现在[com.android] .support:support-compat:28.0.0-alpha3] AndroidManifest.xml:22:18-91 value =(android.support.v4.app.CoreComponentFactory).建议:在AndroidManifest.xml:6:5-40:19中添加'tools:replace ="android:appComponentFactory"'来覆盖.

android android-studio android-design-library android-9.0-pie

90
推荐指数
10
解决办法
15万
查看次数

什么是Jetifier?

什么是Jetifier?例如,要使用androidx打包的依赖项创建一个新项目,这个新项目需要将以下行添加到gradle.properties文件中:

android.enableJetifier=true
Run Code Online (Sandbox Code Playgroud)

那是什么意思 - "启用jetifier"?

android gradle androidx

80
推荐指数
5
解决办法
4万
查看次数

在'android'包中找不到属性'appComponentFactory'的资源标识符

我使用谷歌材料设计作为这个https://material.io/develop/android/docs/getting-started/但是当同步项目我有以下错误

在'android'包中找不到属性'appComponentFactory'的资源标识符消息{kind = ERROR,text =在'android'包中找不到属性'appComponentFactory'的资源标识符,sources = [\?\ E:\ Projects\xoxo- android\app\build\intermediates\manifests\full\debug\AndroidManifest.xml:17],原始消息=,工具名称= Optional.of(AAPT)}

这是我的build.gradle文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

    defaultConfig {
        applicationId "com.example.official2.xoxo"
        minSdkVersion 17
        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 {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.0.1'
    compile 'org.apache.httpcomponents:httpclient:4.5'
    compile 'com.mcxiaoke.volley:library-aar:1.0.0'
    compile 'com.android.support:design:26.0.1'
    compile 'com.google.android.gms:play-services-appindexing:8.1.0'
    compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'
    compile …
Run Code Online (Sandbox Code Playgroud)

android

32
推荐指数
4
解决办法
4万
查看次数

带有片段和FragmentActivity的TabHost

我正在研究Android应用程序,我想使用3个选项卡为每个选项卡使用Fragments进行导航,但我不知道如何创建这样做的结构.

我想分别添加每个片段,因为每个片段都不同,但我不知道在FragmentActivity中将它们添加到何处.

我有这些文件.

tabs_layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="match_parent"
    android:layout_width="match_parent">

    <TabHost android:id="@android:id/tabhost"
         android:layout_width="match_parent"
         android:layout_height="match_parent">

         <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

             <TabWidget
                android:id="@android:id/tabs" 
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
             />

             <FrameLayout
                 android:id="@android:id/tabcontent" 
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"

             >

                 <FrameLayout
                     android:id="@+id/tabRateAPet" 
                     android:layout_width="match_parent"
                     android:layout_height="match_parent"

                 />

                 <FrameLayout
                     android:id="@+id/tabViewMyRates" 
                     android:layout_width="match_parent"
                     android:layout_height="match_parent"

                 />

                 <FrameLayout
                     android:id="@+id/tabViewGlobalRates" 
                     android:layout_width="match_parent"
                     android:layout_height="match_parent"

                 />


             </FrameLayout>
        </LinearLayout>
    </TabHost>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

TabsMain.java

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;

public class MainTabsActivity extends FragmentActivity {
public static final String RATE_A_PET = "Rate a Pet";
public static final String MY_RATES = "My Rates";
public static final …
Run Code Online (Sandbox Code Playgroud)

android android-tabhost android-fragments android-fragmentactivity

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

有没有办法在Android Studio编辑器中显示RecyclerView的内容预览为网格?

当我将RecyclerView添加到布局时,它以垂直顺序显示为列表视图.我正在使用tools:listitem这个.有没有办法,它在Android Studio编辑器中显示为网格而不是列表?

android android-studio android-recyclerview

27
推荐指数
5
解决办法
6635
查看次数