小编Sky*_*sey的帖子

以编程方式设置android形状颜色

我正在编辑以使问题更简单,希望这有助于获得准确的答案.

说我有以下oval形状:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
    <solid android:angle="270"
           android:color="#FFFF0000"/>
    <stroke android:width="3dp"
            android:color="#FFAA0055"/>
</shape>
Run Code Online (Sandbox Code Playgroud)

如何在活动类中以编程方式设置颜色?

android shape android-layout

149
推荐指数
9
解决办法
11万
查看次数

在Gradle中,有更好的方法来获取环境变量吗?

在几个任务中,我引用了我的主文件夹中的jar.

是否有更好的方法来获取环境变量

ENV = System.getenv()
HOME = ENV['HOME']

task copyToServer(dependsOn: 'jar', type: Copy) {

 from 'build/libs/'
 into HOME + "/something/plugins/"
}
Run Code Online (Sandbox Code Playgroud)

这设置了$ HOME,但我希望我从文档中错过了一些魔法.

gradle

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

如何使用单个TextWatcher多个EditTexts?

EditText我的视图布局中有三个小部件.有没有办法TextWatcher为所有三个人使用单身EditTexts

android textwatcher

118
推荐指数
9
解决办法
7万
查看次数

你如何检查android中的互联网连接?

我想检查每项活动的互联网连接.如果丢失,则应显示消息.

任何人都可以指导我如何实现这一目标吗?

android network-state android-activity

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

通知无法在Android Oreo中显示(API 26)

尝试在Android O上显示通知时,我收到此消息.

对于音量控制以外的操作,不推荐使用流类型

该通知直接来自示例文档,并在Android 25上显示正常.

android push-notification android-8.0-oreo android-8.1-oreo

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

在通知中使用ConstraintLayout时崩溃

InflationException当我ConstraintLayout在自定义中使用a时,我得到了一个Notification.我可以在我的应用程序的其他地方使用它们,而不是在自定义布局中Notification.我假设支持库中包含的任何小部件根本无法在a中使用RemoteView,但我找不到任何确认.有人知道吗?

E/StatusBar: couldn't inflate view for notification com.example.app/0x1
android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.ConstraintLayout" on path: DexPathList[[],nativeLibraryDirectories=[/system/priv-app/TeleService/lib/arm64, /system/fake-libs64, /system/priv-app/TeleService/TeleService.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64, /system/lib64, /vendor/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at android.view.LayoutInflater.createView(LayoutInflater.java:606)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    at android.widget.RemoteViews.inflateView(RemoteViews.java:3278)
    at android.widget.RemoteViews.-wrap1(Unknown …
Run Code Online (Sandbox Code Playgroud)

java android android-notifications android-constraintlayout

19
推荐指数
2
解决办法
3110
查看次数

检测是否从Google Play和Amazon vs Other下载了Android应用

我知道这可能是一个远景,但有没有办法以编程方式检测应用程序是否托管在亚马逊应用商店和Google Play上?我想链接到应用程序从应用程序商店下载,如果可以避免的话,我宁愿没有两个不同的APK.

android amazon-appstore google-play

17
推荐指数
1
解决办法
4153
查看次数

Android Vector资产:dp测量只对"包装内容"有影响吗?

当我创建一个矢量drawable时,我可以设置它的大小dp.默认值为24dp x 24dp.

  1. 如果我在我的应用程序中使用不同于24dp x 24dp的矢量,那么这些测量在性能方面是否重要?另外关于21岁以下的API(我app:srcCompat用来显示图像).

  2. 当使用较低的API并且系统将其缩小时,矢量大小是否重要?

  3. 这些测量对我的使用是否重要,除了我申请时只是默认大小wrap_content

android vector

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

使Closure编译器条带日志功能使用



我有一个日志API我想要暴露给一些内部JS代码.我希望能够使用此API进行记录,但仅限于我进行调试构建时.现在,我有部分工作.它只记录调试版本,但是当有常规版本时,对此API的调用仍然在代码中.当我使用goog.DEBUG = false编译时,我希望闭包编译器删除这个基本上死的代码.

日志定义:

goog.provide('com.foo.android.Log');
com.foo.Log.e = function(message){
    goog.DEBUG && AndroidLog.e(message);
}
goog.export(com.foo.Log, "e", com.foo.Log.e);
Run Code Online (Sandbox Code Playgroud)

AndroidLog是一个提供给webview的Java对象,它将在其中运行,并且可以像这样正确地激活:

var AndroidLog = {};

/**
 * Log out to the error console
 * 
 * @param {string} message The message to log
 */
AndroidLog.e = function(message) {};
Run Code Online (Sandbox Code Playgroud)

然后,在我的代码中,我可以使用:

com.foo.Log.e("Hello!"); // I want these stripped in production builds
Run Code Online (Sandbox Code Playgroud)

我的问题是:我如何提供此API,在我的代码中使用此API,但是在未使用goog.DEBUG = true编译时,是否删除了对此API的任何调用?现在,我的代码库变得臃肿,一堆从未调用的Log API调用.我想删除.

谢谢!

javascript google-closure-compiler

12
推荐指数
1
解决办法
1003
查看次数

Gradle:仅解析所需变体的依赖关系

我有一个有三种口味的测试应用程序:

  • dev:在开发期间使用库的本地副本
  • qa:在QA期间使用快照
  • rc:使用预发布版本进行候选发布测试.

dependencies {
  devCompile project(':library')
  qaCompile 'com.example:library:1.0.0-SNAPSHOT@aar'
  rcCompile 'com.example:library:1.0.0@aar'
}
Run Code Online (Sandbox Code Playgroud)

我运行Gradle,并期望它完成所需的最少工作量来构建我想要的东西:

./gradlew :test-app:connectedAndroidTestDevDebug
Run Code Online (Sandbox Code Playgroud)

但是,构建失败,因为它正在尝试解决所有构建风格的依赖关系,而不仅仅是我正在构建的关联.

FAILURE:构建因异常而失败.

*什么地方出了错:

配置项目':test-app'时出现问题.

无法解析配置':test-app:_qaDebugCompile'的所有依赖项.

找不到com.example:library1.0.0-SNAPSHOT.

Searched in the following locations:
     https://repo1.maven.org/maven2/com/example/library/1.0.0-SNAPSHOT/maven-metadata.xml
     https://repo1.maven.org/maven2/com/example/library/1.0.0-SNAPSHOT/library-1.0.0-SNAPSHOT.pom
     https://repo1.maven.org/maven2/com/example/library/1.0.0-SNAPSHOT/library-1.0.0-SNAPSHOT.aar
     http://oss.sonatype.org/content/repositories/snapshots/com/example/library/1.0.0-SNAPSHOT/maven-metadata.xml
     http://oss.sonatype.org/content/repositories/snapshots/com/example/library/1.0.0-SNAPSHOT/library-1.0.0-SNAPSHOT.pom
     http://oss.sonatype.org/content/repositories/snapshots/com/example/library/1.0.0-SNAPSHOT/library-1.0.0-SNAPSHOT.aar
     file:/opt/android-sdk-macosx/extras/android/m2repository/com/example/library/1.0.0-SNAPSHOT/maven-metadata.xml
     file:/opt/android-sdk-macosx/extras/android/m2repository/com/example/library/1.0.0-SNAPSHOT/library-1.0.0-SNAPSHOT.pom
     file:/opt/android-sdk-macosx/extras/android/m2repository/com/example/library/1.0.0-SNAPSHOT/library-1.0.0-SNAPSHOT.aar
     file:/opt/android-sdk-macosx/extras/google/m2repository/com/example/library/1.0.0-SNAPSHOT/maven-metadata.xml
     file:/opt/android-sdk-macosx/extras/google/m2repository/com/example/library/1.0.0-SNAPSHOT/library-1.0.0-SNAPSHOT.pom
     file:/opt/android-sdk-macosx/extras/google/m2repository/com/example/library/1.0.0-SNAPSHOT/library-1.0.0-SNAPSHOT.aar
 Required by:
     project-name:test-app:unspecified
Run Code Online (Sandbox Code Playgroud)

qa味道试图解决的SNAPSHOT 还不存在,这应该没问题,因为我不想尝试建立qa味道.如果存在SNAPSHOT构建,那么一切正常.

问题:

  1. 为什么所有构建版本的依赖项都已解决?
  2. 如何在不遇到这个问题的情况下完成一种风味的构建?
  3. 有没有更好的方法来做更多的"格拉德利"?

android gradle maven

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