小编dev*_*dev的帖子

如何在android中更改默认的ProgressDialog圆圈颜色

ProgressDialog用来显示进度条

            ProgressDialog progressDialog = new ProgressDialog(context);
            progressDialog.setCancelable(false);
            progressDialog.setMessage(message);
            progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            progressDialog.show();
Run Code Online (Sandbox Code Playgroud)

它就是这样的

在此输入图像描述

我想将圆圈的绿色更改为红色.有什么办法吗?

我试过了

.getIndeterminateDrawable().setColorFilter(0xFFFFFFFF, android.graphics.PorterDuff.Mode.MULTIPLY);
Run Code Online (Sandbox Code Playgroud)

但不行.

android android-progressbar

34
推荐指数
6
解决办法
5万
查看次数

如何安装域作为gradle依赖?

我对领域完全陌生.我想在我的android项目中使用realm db.我已经阅读了官方的Realm文档.我需要在我的android项目中设置领域.为此,我已将gradle依赖性添加为

    buildscript {
            repositories {
                     jcenter()
                         }
            dependencies {
                classpath "io.realm:realm-gradle-plugin:0.88.2"
           }
       }
 apply plugin: 'realm-android'
Run Code Online (Sandbox Code Playgroud)

这是他们在文档中给出的.但这对我不起作用.它给出了错误说法Plugin with id 'realm-android' not found.

这是我的build.gradle文件

apply plugin: 'com.android.application'
apply plugin: 'realm-android'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.db.realmsample"
    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath "io.realm:realm-gradle-plugin:0.88.2"
    }
  }

 }

 dependencies {
  compile …
Run Code Online (Sandbox Code Playgroud)

android realm

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

如何将浮动操作按钮对齐到中心

我有一个FloatingActionButton.我希望它是2个LinearLayouts的中间和这样的屏幕中心. 在此输入图像描述

目前我的设计是这样的

在此输入图像描述

我希望它在屏幕的正中心.怎么做?

这是我的整个xml代码

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <LinearLayout
        android:id="@+id/viewA"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1.6"
        android:orientation="horizontal"/>
    <LinearLayout
        android:id="@+id/viewB"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.2"
        android:orientation="horizontal"/>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:src="@drawable/ic_plus"
    app:layout_anchor="@id/viewA"
    android:layout_centerHorizontal="true"
    app:layout_anchorGravity="bottom"
    android:layout_centerInParent="true" />
Run Code Online (Sandbox Code Playgroud)

android android-xml floating-action-button

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

如何动态更改TextView的背景颜色?

我已经提到了这个问题,并使用circle.xml (在res/drawable中)为TextView实现循环背景,并将其设置android:background="@drawable/circle"为TextView.但我需要的是,我需要通过代码动态设置背景颜色.就像棒棒糖联系应用程序,如下所示

在此输入图像描述

我该如何实现这一目标?我需要圆形的TextView背景,如上图所示

android textview background-drawable

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

在类之间传递上下文引用的正确方法是什么?

在我的应用程序中,我在不同的地方引用上下文,包括Intent,访问资源,文件操作,AlertDialog等.而且难以在不同的类中传递当前上下文.所以我尝试在启动器活动中的单例类中设置应用程序基础上下文.因此,在启动应用程序时,我正在获取应用程序上下文并将其设置为类.后来我指的是该上下文的相同实例.但是在某些地方AlertDialog,如果我使用基本上下文,它就会出错.那么,将上下文保持在一个公共位置并访问相同而不是在不同类之间传递当前上下文是一种好的做法吗?或者在不同类之间进行通信时传递上下文的优先方式是什么?

这是我获取上下文的课程

public class AppContext extends Application {
    private static Context sContext = null;
   @Override
    public void onCreate() {
        super.onCreate();
        sContext = getApplicationContext();
    }

    public static Context getContext() {
        return sContext;
    }
}
Run Code Online (Sandbox Code Playgroud)

android android-context

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

Http方法在android studio中不推荐使用警告

我试图用参数做一些http请求.目前我正在使用

 private List<NameValuePair> mParams = new ArrayList<NameValuePair>();
 private DefaultHttpClient mHttpClient;
 private HttpPost mHttpPost;
Run Code Online (Sandbox Code Playgroud)

这些用于发出http请求,它工作正常.但问题是android studio显示所有这些3的弃用警告.我尝试使用, HttpClientBuilder.create().build();但android工作室无法导入库HttpClientBuilder 我尝试下载并添加 此jar依赖 但仍然无法正常工作.这是我的代码

        mHttpClient = new DefaultHttpClient();
        mHttpPost = new HttpPost(url);
        mParams.add(new BasicNameValuePair("key", value));
        mHttpPost.setEntity(new UrlEncodedFormEntity(mParams));
Run Code Online (Sandbox Code Playgroud)

所有这些行都显示了已弃用的警告,这是另一种方法吗?

android deprecated androidhttpclient android-studio

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

Hashmap返回引用而不是副本

我有一个名为Person with properties的模型

name
image
age
amount
Run Code Online (Sandbox Code Playgroud)

我有一个Hashmap<String,Person> globalPersonList包含人物对象列表的单例哈希映射.

我试图从我的hashmap中检索一个单个对象

Person existingPerson = globalPersonList.get("key");
Run Code Online (Sandbox Code Playgroud)

我想PersonexistingPerson类似的属性创建一个新实例并初始化

Person person = new Person();
person  =  globalPersonList.get("key");
Run Code Online (Sandbox Code Playgroud)

现在我想将amount字段设置为此person对象.我尝试过

newPerson.setAmount(100); 
Run Code Online (Sandbox Code Playgroud)

但它不应该影响globalPersonList.我只想在我的newPerson对象中使用金额值.但是现在globalPersonList也是如此.设定金额后,如果我尝试

globalPersonList.get("key").getAmount()
Run Code Online (Sandbox Code Playgroud)

它给出了我设定的金额.它是否使用对新对象的引用?我想要一个Person对象的单独副本,这样它就不会影响主hashmap.

java hashmap

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