ANDROID ERROR- error: cannot access zzbfm class file for com.google.android.gms.internal.zzbfm not found

//   all previously added play-services has version 11.8.0
 implementation 'com.google.android.gms:play-services-auth:11.8.0'   
 implementation 'com.google.android.gms:play-services:11.8.0' 
//   newly added gradle library to add the firebase to app 
 implementation 'com.google.firebase:firebase-core:16.0.0'
As I come accross below error after adding firebse to my app.
 Compilation failed; see the compiler error output for details. 
error: cannot access zzbfmclass file for 
com.google.android.gms.internal.zzbfm not found 
As you can see above that version of firebase-core gradle is 16.0.0, is different
from the other gms:play services (version 11.8.0).
Latest Individual Google Play Services APIs and corresponding build.gradle descriptions:
https://developers.google.com/android/guides/setup
Firebase Android Release Notes: Latest SDK versions Service - Gradle dependency:
https://firebase.google.com/support/release-notes/android
or you can also change the all library/dependency versions to same (or latest--not
tested by me ref issue:  mixing libraries from
 old and new Firebase release and 
other link: Class file for com.google.android.gms.internal.zzaja not found ).
So, I changed to firebase-core to version 11.8.0
 //   all previously added play-services has version 11.8.0
 implementation 'com.google.android.gms:play-services-auth:11.8.0'
 implementation 'com.google.android.gms:play-services:11.8.0' 
//   newly added gradle to add the firebase to app
 implementation 'com.google.firebase:firebase-core:11.8.0'


with my latest project with targetSdkVersion 28, below gradles working fine:

// firebase dependencies
    implementation 'com.google.firebase:firebase-dynamic-links:16.1.5'
    implementation 'com.google.firebase:firebase-appindexing:16.0.2'
    implementation 'com.google.firebase:firebase-core:16.0.4'
    implementation 'com.google.firebase:firebase-messaging:17.3.3'

//gms play services
    implementation 'com.google.android.gms:play-services-ads-lite:16.0.0'
    implementation 'com.google.android.gms:play-services-analytics:16.0.4'
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
    implementation 'com.google.android.gms:play-services-gcm:16.0.0'

Also using the following google play services plugin in the top (Project) level build.gradle file:
classpath 'com.google.gms:google-services:4.2.0'


Please share your latest project working gradle dependencies in Comment. Thanks..

Find Below App and Project level build.gradle file
(Module: app) level build.gradle file with com.google.firebase and android.gms:play-services dependencies :
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'io.fabric'

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
    }
}

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'

    defaultConfig {
        applicationId "com.example_app"

//        API Level: 17 Android 4.2 (JELLY_BEAN_MR1)
        minSdkVersion 17
//Android 4.1 (JELLY_BEAN) 16
// minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
        resConfigs "en"
    }

//    put below code to increase stack size of the thread,
//    aslo remove comment from build.properties  org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
    testOptions {
        unitTests.all {
            jvmArgs '-XX:MaxPermSize=1024m' //prevent OOM (PermGen space) while running tests
        }
    }

    dexOptions {
        javaMaxHeapSize "4g"
//        incremental true
    }

    aaptOptions {
        cruncherEnabled false
    }

    dataBinding {
        enabled = true
    }

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

            jniDebuggable false
            renderscriptDebuggable false
            pseudoLocalesEnabled false
            zipAlignEnabled true
            debuggable false
        }
     
        debug {
            debuggable true
            jniDebuggable true
            renderscriptDebuggable true
            minifyEnabled false
            zipAlignEnabled false
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')

// firebase dependencies
    implementation 'com.google.firebase:firebase-dynamic-links:16.1.5' //
    implementation 'com.google.firebase:firebase-appindexing:16.0.2' //
    implementation 'com.google.firebase:firebase-core:16.0.4'
    implementation 'com.google.firebase:firebase-messaging:17.3.3'

//gms play services
    implementation 'com.google.android.gms:play-services-ads-lite:16.0.0'
    implementation 'com.google.android.gms:play-services-analytics:16.0.4'
    implementation 'com.google.android.gms:play-services-auth:16.0.1'

// support libraries android
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.browser:browser:1.0.0'

    implementation 'androidx.vectordrawable:vectordrawable-animated:1.0.0'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'androidx.mediarouter:mediarouter:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'

    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'

    implementation 'androidx.cardview:cardview:1.0.0'

    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0'


//other library gradle
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.android.volley:volley:1.1.1'
    implementation 'com.j256.ormlite:ormlite-android:4.46'
    implementation 'com.facebook.android:facebook-login:[4,5)'

    implementation 'com.github.castorflex.smoothprogressbar:library:1.1.0'

    //calligraphy
    implementation 'io.github.inflationx:calligraphy3:3.1.1'
    implementation 'io.github.inflationx:viewpump:2.0.3'

    //glide dependency
    implementation 'com.github.bumptech.glide:glide:4.10.0'
    kapt 'com.github.bumptech.glide:compiler:4.10.0'

    //butterknife dependency
    implementation 'com.jakewharton:butterknife:10.1.0'
    kapt 'com.jakewharton:butterknife-compiler:10.1.0'
}
apply plugin: 'com.google.gms.google-services'

(Module: Project) level build.gradle file using latest google services plugin 4.2.0 and
build:gradle version 3.5.2
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    ext.kotlin_version = '1.3.40'

    repositories {
        jcenter()
        google()
        mavenCentral()
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.2'
        classpath 'com.google.gms:google-services:4.2.0'
        classpath 'io.fabric.tools:gradle:1.26.1'
        // NOTE: Do not place your application dependencies here; they belongs
        // in the individual module build.gradle files
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        jcenter()
        google()
        maven {
            url 'https://maven.google.com/'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir

}

Input dispatching timed out Waiting because no window has focus but there is a focused application

ANDROID ANR CRASH LOG:
Input dispatching timed out (AppWindowToken{3e960e4 token=Token{402c77 ActivityRecord{2996e76 u0 com.app.demoapp/.MainActivity t911}}}, Waiting because no window has focus but there is a focused application that may eventually add a window when it finishes starting up.)

org.gradle.api.gradleexception: lint found fatal errors while assembling a release target.

How to find error details:
1) Anylyze -> Inspect Code
2) Then in Inspection Results you will see an error
3) In my case build failed due to "Suspicious namespace and prefix combination" in the layout deceleration as shown blow code:
xmlns:app="http://schemas.android.com/tools"
(Suspicious namespace and prefix combination)
Also, find similar error issues: unresolved javadoc reference in Google IAP and see how to find such error details

SOLUTION CODE:
change the code xmlns:app="http://schemas.android.com/tools" with this: xmlns:app="http://schemas.android.com/apk/res-auto"


ANDROID STUDIO ERROR LOG:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:lintVitalRelease'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:103)
 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:73)
 at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
 at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
 at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
 at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
 at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
 at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
 at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
 at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
 at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
 at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
 at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
 at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
 at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:256)
 at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
 at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328
 at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
 at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
 at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:249)
 at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:238)
 at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
 at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
 at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
 at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
 at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:663)
 at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:597)
 at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
 at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:59)
 at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:130)
 at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
 at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
 at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
 at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
 at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:46)
 at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
 at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
 at org.gradle.initialization.DefaultGradleLauncher$ExecuteTasks.run(DefaultGradleLauncher.java:336)
 at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
 at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
 at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
 at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
 at org.gradle.initialization.DefaultGradleLauncher.runTasks(DefaultGradleLauncher.java:210)
 at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:140)
 at org.gradle.initialization.DefaultGradleLauncher.executeTasks(DefaultGradleLauncher.java:115)
 at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:78)
 at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:75)
 at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:152)
 at org.gradle.internal.invocation.GradleBuildController.doBuild(GradleBuildController.java:100)
 at org.gradle.internal.invocation.GradleBuildController.run(GradleBuildController.java:75)
 at org.gradle.tooling.internal.provider.runner.BuildModelActionRunner.run(BuildModelActionRunner.java:53)
 at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
 at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
 at org.gradle.tooling.internal.provider.ValidatingBuildActionRunner.run(ValidatingBuildActionRunner.java:32)
 at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$1.run(RunAsBuildOperationBuildActionRunner.java:43)
 at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
 at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
 at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
 at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
 at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:40)
 at org.gradle.tooling.internal.provider.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:51)
 at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:49)
 at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:32)
 at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:39)
 at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:25)
 at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:80)
 at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:53)
 at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:57)
 at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:32)
 at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:36)
 at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:25)
 at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:43)
 at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:29)
 at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:64)
 at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:29)
 at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:59)
 at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:44)
 at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:45)
 at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:30)
 at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
 at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
 at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
 at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
 at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
 at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
 at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
 at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
 at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
 at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
 at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
 at org.gradle.util.Swapper.swap(Swapper.java:38)
 at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
 at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
 at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
 at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
 at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:62)
 at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
 at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
 at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:82)
 at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
 at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
 at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
 at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:295)
 at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
 at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
 at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
 at java.lang.Thread.run(Thread.java:745)

Caused by: org.gradle.api.GradleException: Lint found fatal errors while assembling a release target.
To proceed, either fix the issues identified by lint, or modify your build script as follows:

...

android {

    lintOptions {

        checkReleaseBuilds false

        // Or, if you prefer, you can continue to check for errors in release builds,

        // but continue the build even when errors are found:

        abortOnError false

    }

}

...
 at com.android.tools.lint.gradle.LintGradleExecution.abort(LintGradleExecution.java:206)
 at com.android.tools.lint.gradle.LintGradleExecution.runLint(LintGradleExecution.java:297)
 at com.android.tools.lint.gradle.LintGradleExecution.lintSingleVariant(LintGradleExecution.java:368)
 at com.android.tools.lint.gradle.LintGradleExecution.analyze(LintGradleExecution.java:91)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at com.android.tools.lint.gradle.api.ReflectiveLintRunner.runLint(ReflectiveLintRunner.kt:38)
 at com.android.build.gradle.tasks.LintBaseTask.runLint(LintBaseTask.java:88)
 at com.android.build.gradle.tasks.LintPerVariantTask.lint(LintPerVariantTask.java:41)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
 at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:46)
 at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
 at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
 at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:788)
 at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:755)
 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:124)

 at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
 at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
 at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
 at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:113)
 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:95)
 ... 108 more

Change the typeface of ProgressDialog in Android

Here, below example uses CustomFontDialog style to change the font of progressBar message from default to custom.
This example uses setCustomTitle() method to change progressDialog title font to custom.

MainActivity.java
package com.example.espl.changeprogressdialogfontdemo;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.view.ContextThemeWrapper;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private ProgressDialog pDialog;
    Button button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button=findViewById(R.id.btn);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showProgressDialog(MainActivity.this,"Please wait..","Loading data in page",true);
            }
        });
    }

    public void showProgressDialog(Context context, String Title, String Message, boolean isCancelable) {
        try {
            if (pDialog == null)
                //                pDialog = new ProgressDialog(context);
                //use the Custom theme
             //To change android Progress Dialog message typeface
                pDialog = new ProgressDialog(new ContextThemeWrapper(context, R.style.CustomFontDialog));

            if (Title != null && Title.length() > 0){
                //                                pDialog.setTitle(Title);
                TextView tv_title = new TextView(this);
                tv_title.setText(Title);
                tv_title.setTextSize(dpToPxl(10));
                tv_title.setPadding(dpToPxl(15),dpToPxl(5),0,dpToPxl(5));
                tv_title.setTextColor(Color.RED);
                Typeface typeface = ResourcesCompat.getFont(context, R.font.work_sans_regular);
                tv_title.setTypeface(typeface);
//                To Change progressDialog title font to custom
                pDialog.setCustomTitle(tv_title);
            }

            if (Message != null && Message.length() > 0){
                pDialog.setMessage(Message);
            }

            pDialog.setCancelable(isCancelable);

            if (context instanceof Activity) {
                if (!((Activity) context).isFinishing()) {
                    pDialog.show();
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static int dpToPxl(int dp) {
        return (int) (dp * Resources.getSystem().getDisplayMetrics().density);
    }
}

styles.xml
<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="CustomFontDialog" parent="Theme.AppCompat.Light.Dialog">
        <item name="android:fontFamily">@font/work_sans_regular</item>
    </style>
</resources>

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp"
    tools:context=".MainActivity"
    android:background="#f9fff5">

    <Button
        android:id="@+id/btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Show progressDialog with custom font for title and message"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</RelativeLayout>

Default theme for ProgressDialog title and messag font
Default theme font for title and message

Change android Progress Dialog message typeface and custom font for title
Custom font for title and message


This Activity already has an action bar supplied by the window decor

02-11 12:20:19.602 30092-30092/com.elitech.offers.coupons.deals E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.elitech.offers.coupons.deals, PID: 30092
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.elitech.offers.coupons.deals/com.elitech.offers.coupons.deals.NetWork.NetworkConstatnt.NoInternetConnectionActivity_RestartApp}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2429)
        at android.app.ActivityThread.access$800(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
        at android.os.Handler.dispatchMessage(Handler.java:110)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:5333)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
        at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
        at android.support.v7.app.AppCompatDelegateImpl.setSupportActionBar(AppCompatDelegateImpl.java:345)
        at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:130)
        at com.elitech.offers.coupons.deals.NetWork.NetworkConstatnt.NoInternetConnectionActivity_RestartApp.onCreate(NoInternetConnectionActivity_RestartApp.java:41)
        at android.app.Activity.performCreate(Activity.java:5343)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2331)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2429)
        at android.app.ActivityThread.access$800(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
        at android.os.Handler.dispatchMessage(Handler.java:110)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:5333)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
        at dalvik.system.NativeStart.main(Native Method)


        <style name="AppTheme" parent="Theme.AppCompat.Light">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/header</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/header</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
        <item name="actionBarStyle">@style/MyActionBar</item>
        <item name="android:itemTextAppearance">@style/MyActionBar.MenuTextStyle</item>
        <item name="android:windowDisablePreview">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:itemBackground">@color/header</item>
        <item name="android:textColorSecondary">@color/white</item>
    </style>

How to change CollapsingToolbarLayout typeface in android programmatically

ScrollingActivity.java
package com.example.espl.collapsingtoolbarlayoutsetfont;

import android.graphics.Typeface;
import android.os.Bundle;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;

public class ScrollingActivity extends AppCompatActivity {

    CollapsingToolbarLayout toolbarLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_scrolling);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        toolbarLayout=findViewById(R.id.toolbar_layout);
        Button btn=findViewById(R.id.btn);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
//set custom font for CollapsingToolbarLayout title
                    Typeface typeface = ResourcesCompat.getFont(ScrollingActivity.this, R.font.work_sans_regular);
                    toolbarLayout.setCollapsedTitleTypeface(typeface);
                    toolbarLayout.setExpandedTitleTypeface(typeface);
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        });
    }
}

activity_scrolling.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".ScrollingActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:toolbarId="@+id/toolbar">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

            <TextView
                android:text="@string/initial_large_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <Button
                android:id="@+id/btn"
                android:text="Click to change the font for CollapsingToolbarLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/text_margin"
                android:text="@string/large_text" />

        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom|end"
        app:srcCompat="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>

Add the font file in the res/font/ folder to bundle fonts as resources. To access a font resource, use @font/myfont, or R.font.myfont.Using fonts programmatically



Android UI: creating imageview with rounded top corners in android

Android UI: creating imageview with rounded top corners in android
Android cardview only top corner radius works on APIs >= Android 5.0 API. Find these two reference links:
CardView
Android CardView corner radius not applying in Kitkat

frame.xml
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:bottom="-25dp"
        android:left="-25dp"
        android:right="-25dp"
        android:top="-25dp">

        <shape android:shape="rectangle">
            <stroke
                android:width="25dp"
                android:color="#ffffff" />

            <corners android:topRightRadius="40dp"
                android:topLeftRadius="40dp"
                android:bottomLeftRadius="0dp"
                android:bottomRightRadius="0dp"/>
        </shape>
    </item>
</layer-list>

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:orientation="horizontal"
    android:background="#ffffff"
    tools:context=".MainActivity">

    <ImageView
        android:layout_gravity="left"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:src="@drawable/frame"
        android:scaleType="fitXY"
        android:adjustViewBounds="true"
        android:background="@drawable/image1"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <android.support.v7.widget.CardView
        android:id="@+id/card_view"
        app:cardCornerRadius="20dp"
        android:background="@color/colorPrimary"
        app:cardElevation="0dp"
        android:layout_marginLeft="10dp"
        android:layout_gravity="right"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="-20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageView
            android:layout_width="150dp"
            android:layout_height="170dp"
            android:scaleType="fitXY"
            android:adjustViewBounds="true"
            android:src="@drawable/image1"
            android:paddingBottom="20dp"/>
    </android.support.v7.widget.CardView>
</RelativeLayout>

build.gradle (Module:app)
apply plugin: 'com.android.application'
android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.espl.roundedcornerimage"
        minSdkVersion 15
        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(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:design:28.0.0'
    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'
}

MainActivity.java
package com.example.espl.roundedcornerimage;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

android rounded corners only top

Android Sharedpreferences Example

Best way to use your SharedPrefernces is by using your appContext that is accessible to the whole App(Common SharedPrefernce and accessible Everywhere).

Define your SharedPrefernces instance in your Application class with get and set methods as below : (If you have not created the Application class then create one as below, This class is called at the start of your app)

public class Application extends android.app.Application { 
    private static Application _instance; 
    private static SharedPreferences _preferences;

    @Override
    public void onCreate() {
        super.onCreate();
         _instance = this;
    }

    public static Application get() {
        return _instance;
    }

    /**
     * Gets shared preferences.
     *
     * @return the shared preferences
     */
    public static SharedPreferences getSharedPreferences() {
        if (_preferences == null)
            _preferences = PreferenceManager.getDefaultSharedPreferences(_instance);
        return _preferences;
    }


//set methods
    public static void setPreferences(String key, String value) {
        getSharedPreferences().edit().putString(key, value).commit();
    }

    public static void setPreferences(String key, long value) {
        getSharedPreferences().edit().putLong(key, value).commit();
    }

    public static void setPreferences(String key, int value) {
        getSharedPreferences().edit().putInt(key, value).commit();
    }

    public static void setPreferencesBoolean(String key, boolean value) {
        getSharedPreferences().edit().putBoolean(key, value).commit();
    }

    //get methods
    public static String getPrefranceData(String key) {
        return getSharedPreferences().getString(key, "");
    }

    public static int getPrefranceDataInt(String key) {
        return getSharedPreferences().getInt(key, 0);
    }

    public static boolean getPrefranceDataBoolean(String key) {
        return getSharedPreferences().getBoolean(key, false);
    }

    public static long getPrefranceDataLong(String interval) {
        return getSharedPreferences().getLong(interval, 0);
    }
}
Declare the Application class in AndroidManifest.xml file with line android:name=".Application" as shown in below snippet:

<application
            android:name=".Application"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:largeHeap="true"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
Now, How to store key-value:

Application.setPreferences("Key","String_Value");
How to fetch key-value:

String value_string=Application.getPrefranceData("Key");
You can now set-SharedPrefernce key-value and get-SharedPrefernce value from anywhere in the app using public Application class and the static get and set methods

How to generate unsigned release apk with Android Studio

Using Android studio 3.2.1 to generate the unsigned release apk for the android application 

Here as shown in below image select your app then follow these steps:

1) Build --> Edit build type --> (app)select release--> Ok

2) Build-> Select build Variant-> change from build to release(As shown in below image) --> It will Build gradle and update indices (Let it complete)

3) Build -->Build bundles/apks ->Build apks
 3.1) This wil start making release apk without signing and also you refer second image for the tasks running while bulding release APK.
 It would take time if you have used the Pro-guard (due to classes and resources being transformed during this step).
 After last task "app:assembleRlease", your release APK will get generated.

Attempt to read from field 'android.view.View android.support.v7.widget.RecyclerView$ViewHolder.itemView'

Fatal Exception: java.lang.NullPointerException
Attempt to read from field 'android.view.View android.support.v7.widget.RecyclerView$ViewHolder.itemView' on a null object reference
android.support.v7.widget.DefaultItemAnimator.runPendingAnimations (DefaultItemAnimator.java:157)
android.support.v7.widget.RecyclerView$2.run (RecyclerView.java:589)
android.view.Choreographer$CallbackRecord.run (Choreographer.java:911)
android.view.Choreographer.doCallbacks (Choreographer.java:713)
android.view.Choreographer.doFrame (Choreographer.java:645)
android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:897)
android.os.Handler.handleCallback (Handler.java:815)
android.os.Handler.dispatchMessage (Handler.java:104)
android.os.Looper.loop (Looper.java:207)
android.app.ActivityThread.main (ActivityThread.java:5790)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1015)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:876)

Fatal Exception: java.lang.LinkageError No superclass defined for class com.google.android.gms.ads.nonagon.signals.n

Fatal Exception: java.lang.LinkageError
No superclass defined for class com.google.android.gms.ads.nonagon.signals.n (declaration of 'com.google.android.gms.ads.nonagon.signals.n' appears in /data/user_de/0/com.google.android.gms/app_chimera/m/00000007/AdsDynamite.apk)
dalvik.system.DexFile.defineClassNative (DexFile.java)
dalvik.system.DexFile.defineClass (DexFile.java:282)
dalvik.system.DexFile.loadClassBinaryName (DexFile.java:275)
dalvik.system.DexPathList$Element.findClass (DexPathList.java:677)
dalvik.system.DexPathList.findClass (DexPathList.java:466)
dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java:123)
com.bumptech.glide.load.engine.EngineKeyFactory.loadClass (:com.google.android.gms.dynamite_dynamiteloader@14799051@14.7.99 (040408-223214910):3)
java.lang.ClassLoader.loadClass (ClassLoader.java:312)
com.google.android.gms.ads.nonagon.signals.m.a (:com.google.android.gms.dynamite_adsdynamite@14799051@14.7.99 (040408-223214910):7)
com.google.android.gms.ads.nonagon.signals.cx.a (:com.google.android.gms.dynamite_adsdynamite@14799051@14.7.99 (040408-223214910):6)
com.google.android.gms.ads.nonagon.load.o.a (:com.google.android.gms.dynamite_adsdynamite@14799051@14.7.99 (040408-223214910):7)
aod.a (:com.google.android.gms.dynamite_adsdynamite@14799051@14.7.99 (040408-223214910):9)
com.google.android.gms.ads.nonagon.load.m.a (:com.google.android.gms.dynamite_adsdynamite@14799051@14.7.99 (040408-223214910):16)
aod.a (:com.google.android.gms.dynamite_adsdynamite@14799051@14.7.99 (040408-223214910):9)
com.google.android.gms.ads.nonagon.load.n.a (:com.google.android.gms.dynamite_adsdynamite@14799051@14.7.99 (040408-223214910):15)
aod.a (:com.google.android.gms.dynamite_adsdynamite@14799051@14.7.99 (040408-223214910):9)
com.google.android.gms.ads.nonagon.ad.interstitial.w.a (:com.google.android.gms.dynamite_adsdynamite@14799051@14.7.99 (040408-223214910):9)
aod.a (:com.google.android.gms.dynamite_adsdynamite@14799051@14.7.99 (040408-223214910):9)
com.google.android.gms.ads.nonagon.ad.interstitial.u.a (:com.google.android.gms.dynamite_adsdynamite@14799051@14.7.99 (040408-223214910):2)
com.google.android.gms.ads.nonagon.shim.s.b (:com.google.android.gms.dynamite_adsdynamite@14799051@14.7.99 (040408-223214910):40)
com.google.android.gms.ads.nonagon.shim.j.b (:com.google.android.gms.dynamite_adsdynamite@14799051@14.7.99 (040408-223214910):6)
com.google.android.gms.ads.internal.client.an.dispatchTransaction (:com.google.android.gms.dynamite_adsdynamite@14799051@14.7.99 (040408-223214910):160)
com.google.android.gms.signin.internal.zaf.onTransact (:com.google.android.gms.dynamite_adsdynamite@14799051@14.7.99 (040408-223214910):11)
android.os.Binder.transact (Binder.java:630)
com.google.android.gms.internal.ads.zzej.transactAndReadException (Unknown Source:7)
com.google.android.gms.internal.ads.zzku.zzb (Unknown Source:8)
com.google.android.gms.internal.ads.zzma.zza (Unknown Source:181)
com.google.android.gms.ads.InterstitialAd.loadAd (Unknown Source:6)
com.elitech.offers.coupons.deals.V2.ad.AdSetup.loadInterstatial (AdSetup.java:111)
com.elitech.offers.coupons.deals.V2.Home.tabfragments.HomeFragmentV2.onCreateView (HomeFragmentV2.java:256)
android.support.v4.app.Fragment.performCreateView (Fragment.java:2439)
android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1460)
android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState (FragmentManager.java:1784)
android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1852)
android.support.v4.app.BackStackRecord.executeOps (BackStackRecord.java:802)
android.support.v4.app.FragmentManagerImpl.executeOps (FragmentManager.java:2625)
android.support.v4.app.FragmentManagerImpl.executeOpsTogether (FragmentManager.java:2411)
android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute (FragmentManager.java:2366)
android.support.v4.app.FragmentManagerImpl.execPendingActions (FragmentManager.java:2273)
android.support.v4.app.FragmentManagerImpl.dispatchStateChange (FragmentManager.java:3273)
android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated (FragmentManager.java:3229)
android.support.v4.app.FragmentController.dispatchActivityCreated (FragmentController.java:201)
android.support.v4.app.FragmentActivity.onStart (FragmentActivity.java:620)
android.support.v7.app.AppCompatActivity.onStart (AppCompatActivity.java:178)
com.elitech.offers.coupons.deals.MainActivity.onStart (MainActivity.java:697)
android.app.Instrumentation.callActivityOnStart (Instrumentation.java:1335)
android.app.Activity.performStart (Activity.java:7104)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2777)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2892)
android.app.ActivityThread.-wrap11 (Unknown Source)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1613)
android.os.Handler.dispatchMessage (Handler.java:106)
android.os.Looper.loop (Looper.java:171)
android.app.ActivityThread.main (ActivityThread.java:6635)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:547)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:823)

Android change vector drawable color programmatically

In the xml-file you can set custom color with the attribute android:fillColor but to change the color of vector drawable in runtime/dynamically. Tere is need to Change fillColor of a vector drawable in android programmatically, you can edit fill Color of a vector-file in Android programmatically using DrawableCompat.setTint() method which change tint color of whole vector drawable.

Here, ImageView is set with drawable vector icon of black color. This example changes android ImageView srcCompat vector drawable tint color to colorAccent as defined in the colors.xml.

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center_horizontal"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/button"
        android:padding="10dp"
        android:layout_margin="10dp"
        android:layout_width="wrap_content"
        android:textAllCaps="false"
        android:text="Click to Change Image Vector Drawable Color"
        android:layout_height="wrap_content" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="100dp"
        android:layout_height="100dp"
        app:srcCompat="@drawable/ic_settings_black_24dp"
        android:scaleType="fitCenter" />
    <!--android:tint="@color/colorPrimary"-->
</LinearLayout>


MainActivity.java:
package com.example.espl.changedrawablecolor;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    ImageView imageView;
    Button button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button=findViewById(R.id.button);
        imageView=findViewById(R.id.imageView);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DrawableCompat.setTint(imageView.getDrawable(),ContextCompat.getColor(getApplicationContext(), R.color.colorAccent));
            }
        });
    }
}

How to change color of vector drawable on button click android imageview
Default Color of the ImageView Drawable is black color before button click

Android Change Image Vector Drawable Color programmatically
Changed Color of the ImageView Drawable on button click


build.gradle (Module:app)
apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.espl.changedrawablecolor"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    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'
}


Android change drawable color programmatically

Content
1) Android change color on drawables located in res folder
2) Android change textview drawables color programmatically
3) Source Code

The Android TextView supports displaying a drawable right, left, top and below the text, but how to set drawable tint programmatically to match the text color. In Android, to change drawable tint color is easy using a PorterDuffColorFilter.

Here is example to change textview drawable color programmatically in android. How to change the colour of the compoundDrawables set to the TextView using setColorFilter method which specify a color and Porter-Duff mode to be the color filter for this drawable. There is good explanation of the setColorFilter over at Android Developers.
Note: Setting a color filter disables tint.

Here, TextView is set with drawableRight, drawableTop, drawableLeft and drawableBottom vector icon of black color. This example changes android Textview drawables tint color to different colors as shown in the example code.

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="#D3d3d3"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center_horizontal"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/button"
        android:padding="10dp"
        android:layout_margin="10dp"
        android:layout_width="wrap_content"
        android:textAllCaps="false"
        android:background="@color/colorWhite"
        android:text="Click to Change Textview Drawable color programmatically"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/textView"
        android:background="@color/colorWhite"
        android:textColor="#000000"
        android:drawableRight="@drawable/ic_settings_black_24dp"
        android:drawableTop="@drawable/ic_settings_black_24dp"
        android:drawableLeft="@drawable/ic_settings_black_24dp"
        android:drawableBottom="@drawable/ic_settings_black_24dp"
        android:padding="10dp"
        android:drawablePadding="10dp"
        android:layout_margin="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>


MainActivity.java:
package com.example.espl.changedrawablecolor;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    TextView txt;
    Button button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button=findViewById(R.id.button);
        txt=findViewById(R.id.textView);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                /**
                 * Returns drawables for the left, top, right, and bottom borders.
                 *
                 * @attr ref android.R.styleable#TextView_drawableLeft
                 * @attr ref android.R.styleable#TextView_drawableTop
                 * @attr ref android.R.styleable#TextView_drawableRight
                 * @attr ref android.R.styleable#TextView_drawableBottom
                 */
                Drawable[] compoundDrawables=txt.getCompoundDrawables();

                //To change android textview drawableLeft tint color to MAGENTA programmatically
                Drawable drawableLeft=compoundDrawables[0].mutate();
                drawableLeft.setColorFilter(new PorterDuffColorFilter(Color.MAGENTA, PorterDuff.Mode.SRC_IN));

                //To Change drawableLeft color to BLUE programmatically
                Drawable drawableTop=compoundDrawables[1].mutate();
                drawableTop.setColorFilter(new PorterDuffColorFilter(Color.BLUE, PorterDuff.Mode.SRC_IN));

                //To Change drawableRight color to RED programmatically
                Drawable drawableRight=compoundDrawables[2].mutate();
                drawableRight.setColorFilter(new PorterDuffColorFilter(Color.RED, PorterDuff.Mode.SRC_IN));

                //To Change drawableBottom color to GREEN programmatically
                Drawable drawableBottom=compoundDrawables[3].mutate();
                drawableBottom.setColorFilter(new PorterDuffColorFilter(Color.GREEN, PorterDuff.Mode.SRC_IN));
            }
        });
    }
}

colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#008577</color>
    <color name="colorPrimaryDark">#00574B</color>
    <color name="colorAccent">#D81B60</color>
    <color name="colorGrey">#D3d3d3</color>
    <color name="colorWhite">#FFFFFF</color>
</resources>


android drawable tint color change programmatically
Default Color of the TextView CompoundDrawables is black color before button click
set color filter android drawable programmatically
Changed Colors of the TextView CompoundDrawables on button click 


Source Code
Download demo app example for above code here: ChangeDrawableColor

Note: This method was deprecated in API level 29.
public void setColorFilter (int color,
                PorterDuff.Mode mode)
This method was deprecated in API level 29.
So, It's suggested to use setColorFilter(android.graphics.ColorFilter) with an instance of BlendModeColorFilter

Popular Posts