小编Bry*_*yan的帖子

从应用程序类获取主题属性

我一直在使用一种方法从当前获取颜色属性Context

public static int getColorAttribute(Context context, @AttrRes int attr) {
    final TypedValue value = new TypedValue();
    context.getTheme().resolveAttribute(attr, value, true);
    return value.data;
}
Run Code Online (Sandbox Code Playgroud)

它工作得很好,但是当我尝试在扩展Application它的类中使用它时,它返回0. 在大多数情况下,我会像这样调用方法:

int colorAccent = Util.getColorAttribute(this, R.attr.colorAccent);
Run Code Online (Sandbox Code Playgroud)

这将返回"colorAccent"我集themes.xml作为我AppTheme在我的清单。但是在Application课堂上我不得不调用getApplicationContext()而不是this. 因此,我也将方法的其他实例之一切换到了ActivitytogetApplicationContext()中,它返回了0. 我也尝试过getApplication()getBaseContext()结果相同。

我想知道是否有办法从类中的应用程序主题中获取颜色Application。或者如果没有,为什么getApplicationContext().getTheme()似乎没有返回应用程序主题。

java android android-theme android-styles android-attributes

2
推荐指数
1
解决办法
1782
查看次数

使用com.android.support.constraint的文件:constraint-layout:1.0.0-alpha2

我对Android不是很熟悉,但我朋友的一位朋友说他在我的电脑上为我的网站制作了一个应用程序.所以他发给我源文件,我试图重建应用程序,但它不起作用.我甚至试图在我的计算机上创建一个新项目,并复制/粘贴每个页面的代码.然后只需更改项目名称,但问题与下面的问题相同,我无法再次与他联系,因为他只是为我服务.所以我希望这里有人可以帮我解决这个问题,因为我真的厌倦了尝试解决这个问题.

错误信息是:

Maven package paths must start with m2repository
com.intellij.openapi.diagnostic.Logger$EmptyThrowable
    at com.intellij.openapi.diagnostic.Logger.error(Logger.java:117)
    at com.android.tools.idea.sdk.wizard.InstallSelectedPackagesStep$CustomLogger.logError(InstallSelectedPackagesStep.java:403)
    at com.android.sdklib.repositoryv2.MavenInstaller.install(MavenInstaller.java:102)
    at com.android.tools.idea.sdk.wizard.InstallSelectedPackagesStep$InstallTask.run(InstallSelectedPackagesStep.java:242)
    at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:563)
    at com.intellij.openapi.progress.impl.CoreProgressManager$2.run(CoreProgressManager.java:142)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:446)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:392)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:127)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl$1.run(ProgressManagerImpl.java:126)
    at com.intellij.openapi.application.impl.ApplicationImpl$8.run(ApplicationImpl.java:366)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    at org.jetbrains.ide.PooledThreadExecutor$1$1.run(PooledThreadExecutor.java:55)
Run Code Online (Sandbox Code Playgroud)
apply plugin: 'com.android.application'
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    defaultConfig {
        applicationId "co.berava"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        } …
Run Code Online (Sandbox Code Playgroud)

android android-build android-gradle-plugin

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

在android中开发应用程序有哪些不同的方法?

任何人都可以告诉我有多少种方法可以为Android平台开发应用程序.我所知道的唯一方法是通过Java.我读到的不是Java; Python,Rails和Native C也可用于开发Android应用程序.如果有人知道的话,请帮助我,就如何使用这些语言创建包含任何教程,文档或书籍的应用程序而言.

android

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

中心右侧标题上的UIButton图像

我正在搜索这篇文章并试图自己解决这个问题,但它几乎没有用.

我想UIButton用图像和标题.
UIButton横跨(几乎)整个屏幕.
图像应位于按钮的右边缘.
标题应该在整个按钮中居中.

如何用插图做到这一点?

user-interface uibutton insets ios imageedgeinsets

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

如何在iCloud Drive上备份和恢复.zip文件?

我想在iCloud上存储.zip文件.有人帮我上传和恢复?我已经阅读了iCloud备份的Apple指南,现在我创建了一个包含一些文件的文件夹和两个包含多个图像的文件夹,然后生成该文件夹的zip文件.

iphone objective-c ios icloud

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

使用样式的警报对话框文本颜色

我刚刚在我的应用程序中更新了库版本,现在AlertDialog按钮的文本颜色为白色.在此之前,colorAccent如果我没记错的话,那就是指定它们的属性.我尝试了很多不同的属性,但似乎没有一个属性能够工作.

示例照片 - 在右下方,您可以看到非常隐蔽的按钮:

在此输入图像描述

我当前的警报对话框样式:

<style name="AlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="colorAccent">@color/website_main</item>
    <item name="android:textColor">@color/website_main</item>
</style>
Run Code Online (Sandbox Code Playgroud)

以我的主题风格:

<item name="android:alertDialogStyle">@style/AlertDialogStyle</item>
Run Code Online (Sandbox Code Playgroud)

我正在使用的支持/设计/ appcompat的当前版本是: 25.1.0

我在其中创建的Java代码AlertDialog:

android.support.v7.app.AlertDialog.Builder alertDialogBuilder = new android.support.v7.app.AlertDialog.Builder(activity);
    alertDialogBuilder
            .setCancelable(false)
            .setPositiveButton(activity.getString(R.string.ok), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    <UnrelatedLogic...>
                }
            });
    return alertDialogBuilder.show();
Run Code Online (Sandbox Code Playgroud)

在这里我使用的ListPreference还使用了AlertDialog:

android.support.v7.preference.ListPreference lang_preference = (android.support.v7.preference.ListPreference) findPreference("language_chooser");
Run Code Online (Sandbox Code Playgroud)

有什么建议?

android android-alertdialog android-styles

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

使用@Query 改造 ws 错误

我试过这个界面:

public interface InterfaceWs
{
  @GET("/?extract-mode=bestdeals&api-key={apikey}") public Observable<List<ModelBestDeals>> getBestDeals(@Query("apikey") String apikey);
}
Run Code Online (Sandbox Code Playgroud)

在使用之前,@Query我正在使用@Path. 我更改它并收到此错误:

URL query string "extract-mode=bestdeals&api-key={apikey}" must not have replace block. For dynamic query parameters use @Query.
Run Code Online (Sandbox Code Playgroud)

怎么了 ?

android retrofit

0
推荐指数
1
解决办法
1092
查看次数

RxJava在服务线程上订阅

我创建了一个简单IntentService的文件和一些数据上传到服务器。我希望能够Toast在上传完成时显示,但是我需要在主线程上才能执行此操作。

由于我将RetroFit与RxJava结合使用来处理实际请求,因此我认为我应该使用该observeOn(AndroidSchedulers.mainThread())方法Toast在主线程上创建。问题是(由于服务器的原因)我可能不得不重新发送请求,在这种情况下,我必须postRequest()再次调用该方法。

然后,此新请求现在位于主线程上。因此,为了避免使用该subscribeOn(Schedulers.io())方法,考虑到Service已经在自己的线程上,这似乎是一种浪费。

是否有指定的方式Observable应该subscribeOn()Service线程?还是应该仅继承子类Service而不IntentService使用io线程?

private void postRequest(String title, LatLng location,
                         String description, MultipartBody.Part attachment) {
    mNetworkService.postRequest(title, location.latitude, location.longitude,
            description, attachment).subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(response -> {
                if (response.status() == 1) {
                    ToastUtil.makeText(getApplicationContext(), "Request Sent");
                    stopSelf();
                } else {
                    postRequest(title, location, description, attachment);
                }
            });
}
Run Code Online (Sandbox Code Playgroud)

android android-service rx-java rx-android

0
推荐指数
1
解决办法
1118
查看次数

Kotlin 为在 android 上单击的小部件添加自定义侦听器

我是 Kotiln 的新手,这段代码是我在 Android 上使用的简单类。在这个类中,我想制作简单的侦听器来检测对类内项目的点击,例如活动、片段或适配器。我的问题是我可以为circularProgressView小部件定义这个监听器。

class DownloadProgressView : RelativeLayout {

    var progressListener: ((downloading: Boolean) -> Unit)? = null
    private var downloading = false

    constructor(context: Context?) : super(context) {
        init()
    }

    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
        init()
    }

    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
        init()
    }

    private fun init() {
        LayoutInflater.from(context).inflate(R.layout.download_progress_layout, this)
        circularProgressView.setOnClickListener {
            downloading = !downloading
            setProgressViews(downloading)
            progressListener?.invoke(downloading)

            //if listener!=null then onItemClicked.onClick();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我怎么知道用户是否点击了circularProgressView内部活动?

我正在尝试实现这个接口并在 Kotlin …

android kotlin

0
推荐指数
1
解决办法
6071
查看次数