Packaging: AAR
Name: apk-app-theme
Developer: dbh4ck
Description: APK Theme Changer Library
Url: https://github.com/dbh4ck/db-apk-theme-changer
License: The Apache Software License, Version 2.0
Version: 1.0
Support: Android API 14 or above
Download: available offline(.aar file) Download Here & can be compiled Online with Gradle (2.3 or higher) via jcenter repo.
Year: 2017
Details: A Simple Android AAR Library for the Support of Multi-Theming in Android Applications enhanching users to customize their apps as per the requirements of UI Designing. This Library contains a Dialog Fragment which popup from the bottom screen of the app & let you choose which color theme you want to apply to your apk. Total available themes are 20 by default which can further be modified and used as per the requirements.
How to IMPORT this Library in your android project?
METHOD 1: Download Library as AAR And Import it in your project as per following steps in order.
In order to import a .aar library:
Step 1: Open Android Studio, Go to File > New > New Module. Select "Import .JAR/.AAR Package" and click next.
Step 2: Enter the path to .aar file and click finish.
Step 3: Go to File > Project Structure (Ctrl+Shift+Alt+S). Under "Modules," in left menu, select "app"
Step 4: Go to "Dependencies" tab. Click the green "+" in the upper right corner.
Step 5: Select "Module Dependency" Select the new module from the list and click ok. Youre done importing this library succesfully in your project.
METHOD 2: This Method involve online downloading & compiling library by Gradle using your project's default (jcenter) repositories
Step 1: Go to app-level build.gradle file and add following dependency:
// app-level build.gradle
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
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:25.2.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
compile 'com.android.support:design:25.2.0'
testCompile 'junit:junit:4.12'
compile 'com.dbh4ck:dbtheme:1.0' // This is our APK Theme Changer Library
}
Step 2: Hit "Sync Now" and you're done compiling this Library from my maven repo.
How to USE this Library:
After importing, now you can use this Library in your Activities as follow:
Step 1:
dbThemeDialog dialog = dbThemeDialog.newInstance(); // Create the new Instance of Dialog in an onCreate Method of your Activity
dialog.show(getSupportFragmentManager(), "dialog"); // Show the DialogFragment
Step 2:
Extend your "AppCompatActivity" to BaseActivity of this Library. (Dont Forget to make onCreate method as Public if you got error while building your project)
Open Android Studio >> Create New Project >> Create New Class named BaseActivity and extends it as AppCompatActivity as shown below. Paste following Code :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.blogspot.dbh4ck.dbtheme; | |
import android.os.Build; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.WindowManager; | |
/** | |
* Created by DB on 22-04-2017. | |
*/ | |
public class BaseActivity extends AppCompatActivity { | |
private final static int THEME_PINK_1 = 0; | |
private final static int THEME_PINK_2 = 1; | |
private final static int THEME_PINK_3 = 2; | |
private final static int THEME_BLUE_1 = 3; | |
private final static int THEME_BLUE_2 = 4; | |
private final static int THEME_BLUE_3 = 5; | |
private final static int THEME_RED_1 = 6; | |
private final static int THEME_RED_2 = 7; | |
private final static int THEME_GREEN_1 = 8; | |
private final static int THEME_GREEN_2 = 9; | |
private final static int THEME_GREEN_3 = 10; | |
private final static int THEME_GREEN_4 = 11; | |
private final static int THEME_PURPLE_1 = 12; | |
private final static int THEME_PURPLE_2 = 13; | |
private final static int THEME_BLACK_1 = 14; | |
private final static int THEME_YELLOW_1 = 15; | |
private final static int THEME_BROWN_1 = 16; | |
private final static int THEME_BROWN_2 = 17; | |
private final static int THEME_GREEN_SHADE = 18; | |
private final static int THEME_GREY_SHADE = 19; | |
private final static int THEME_DEFAULT = 20; | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
updateTheme(); | |
} | |
public void updateTheme() { | |
if (Utility.getTheme(getApplicationContext()) == THEME_PINK_1 ) { | |
setTheme(R.style.theme_pink1); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
getWindow().setStatusBarColor(getResources().getColor(R.color.theme_pink1dark)); | |
} | |
} | |
else if (Utility.getTheme(getApplicationContext()) == THEME_PINK_2) { | |
setTheme(R.style.theme_pink2); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
getWindow().setStatusBarColor(getResources().getColor(R.color.theme_pink2dark)); | |
} | |
} | |
else if (Utility.getTheme(getApplicationContext()) == THEME_PINK_3) { | |
setTheme(R.style.theme_pink3); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
getWindow().setStatusBarColor(getResources().getColor(R.color.theme_pink3dark)); | |
} | |
} | |
else if (Utility.getTheme(getApplicationContext()) == THEME_BLUE_1) { | |
setTheme(R.style.theme_blue1); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
getWindow().setStatusBarColor(getResources().getColor(R.color.theme_blue1dark)); | |
} | |
} | |
else if (Utility.getTheme(getApplicationContext()) == THEME_BLUE_2) { | |
setTheme(R.style.theme_blue2); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
getWindow().setStatusBarColor(getResources().getColor(R.color.theme_blue2dark)); | |
} | |
} | |
else if (Utility.getTheme(getApplicationContext()) == THEME_BLUE_3) { | |
setTheme(R.style.theme_blue3); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
getWindow().setStatusBarColor(getResources().getColor(R.color.theme_blue3dark)); | |
} | |
} | |
else if (Utility.getTheme(getApplicationContext()) == THEME_RED_1) { | |
setTheme(R.style.theme_red1); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
getWindow().setStatusBarColor(getResources().getColor(R.color.theme_red1dark)); | |
} | |
} | |
else if (Utility.getTheme(getApplicationContext()) == THEME_RED_2) { | |
setTheme(R.style.theme_red2); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
getWindow().setStatusBarColor(getResources().getColor(R.color.theme_red2dark)); | |
} | |
} | |
else if (Utility.getTheme(getApplicationContext()) == THEME_GREEN_1) { | |
setTheme(R.style.theme_green1); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
getWindow().setStatusBarColor(getResources().getColor(R.color.theme_green1dark)); | |
} | |
} | |
else if (Utility.getTheme(getApplicationContext()) == THEME_GREEN_2) { | |
setTheme(R.style.theme_green2); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
getWindow().setStatusBarColor(getResources().getColor(R.color.theme_green2dark)); | |
} | |
} | |
else if (Utility.getTheme(getApplicationContext()) == THEME_GREEN_3) { | |
setTheme(R.style.theme_green3); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
getWindow().setStatusBarColor(getResources().getColor(R.color.theme_green3dark)); | |
} | |
} | |
else if (Utility.getTheme(getApplicationContext()) == THEME_GREEN_4) { | |
setTheme(R.style.theme_green4); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
getWindow().setStatusBarColor(getResources().getColor(R.color.theme_green4dark)); | |
} | |
} | |
else if (Utility.getTheme(getApplicationContext()) == THEME_PURPLE_1) { | |
setTheme(R.style.theme_purple1); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
getWindow().setStatusBarColor(getResources().getColor(R.color.theme_purple1dark)); | |
} | |
} | |
else if (Utility.getTheme(getApplicationContext()) == THEME_PURPLE_2) { | |
setTheme(R.style.theme_purple2); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
getWindow().setStatusBarColor(getResources().getColor(R.color.theme_purple2dark)); | |
} | |
} | |
else if (Utility.getTheme(getApplicationContext()) == THEME_BLACK_1) { | |
setTheme(R.style.theme_black1); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
getWindow().setStatusBarColor(getResources().getColor(R.color.theme_black1dark)); | |
} | |
} | |
else if (Utility.getTheme(getApplicationContext()) == THEME_YELLOW_1) { | |
setTheme(R.style.theme_yellow1); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
getWindow().setStatusBarColor(getResources().getColor(R.color.theme_yellow1dark)); | |
} | |
} | |
else if (Utility.getTheme(getApplicationContext()) == THEME_BROWN_1) { | |
setTheme(R.style.theme_brown1); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
getWindow().setStatusBarColor(getResources().getColor(R.color.theme_brown1dark)); | |
} | |
} | |
else if (Utility.getTheme(getApplicationContext()) == THEME_BROWN_2) { | |
setTheme(R.style.theme_brown2); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
getWindow().setStatusBarColor(getResources().getColor(R.color.theme_brown2dark)); | |
} | |
} | |
else if (Utility.getTheme(getApplicationContext()) == THEME_GREEN_SHADE) { | |
setTheme(R.style.theme_green_shade); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
getWindow().setStatusBarColor(getResources().getColor(R.color.theme_green_shade_dark)); | |
} | |
} | |
else if (Utility.getTheme(getApplicationContext()) == THEME_GREY_SHADE) { | |
setTheme(R.style.theme_grey); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
getWindow().setStatusBarColor(getResources().getColor(R.color.theme_grey_shade_dark)); | |
} | |
} | |
else if (Utility.getTheme(getApplicationContext()) == THEME_DEFAULT) { | |
setTheme(R.style.NimbuzzTheme); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
getWindow().setStatusBarColor(getResources().getColor(R.color.app_color_primary_dark)); | |
} | |
} | |
} | |
} |
Create another class Utility to get the last saved Theme value Paste the code shown under:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.blogspot.dbh4ck.dbtheme; | |
import android.content.Context; | |
import android.content.SharedPreferences; | |
import android.preference.PreferenceManager; | |
/** | |
* Created by DB on 22-04-2017. | |
*/ | |
public class Utility { | |
public static void setTheme(Context context, int theme) { | |
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); | |
prefs.edit().putInt(context.getString(R.string.prefs_theme_key), theme).apply(); | |
} | |
public static int getTheme(Context context) { | |
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); | |
return prefs.getInt(context.getString(R.string.prefs_theme_key), -1); | |
} | |
} |
Create a DialogFragment which will display list of colors for users to select and apply the selected color theme to the app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.blogspot.dbh4ck.dbtheme; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.graphics.Bitmap; | |
import android.graphics.BitmapFactory; | |
import android.graphics.Canvas; | |
import android.graphics.Color; | |
import android.graphics.Paint; | |
import android.graphics.PorterDuff; | |
import android.graphics.PorterDuffXfermode; | |
import android.graphics.Rect; | |
import android.graphics.RectF; | |
import android.os.Bundle; | |
import android.support.v4.app.DialogFragment; | |
import android.support.v7.widget.LinearLayoutManager; | |
import android.support.v7.widget.RecyclerView; | |
import android.view.Gravity; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.view.WindowManager; | |
import android.widget.ImageView; | |
import android.widget.TextView; | |
import android.widget.Toast; | |
/** | |
* Created by DB on 22-04-2017. | |
*/ | |
public class dbThemeDialog extends DialogFragment implements View.OnClickListener { | |
RecyclerView themesList; | |
TextView cancelTxt; | |
private int[] themes_colors; | |
private MyRecycleAdapter adapter; | |
public static dbThemeDialog newInstance(){ | |
dbThemeDialog f = new dbThemeDialog(); | |
return f; | |
} | |
@Override | |
public void onCreate(final Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setStyle(STYLE_NO_FRAME, DialogFragment.STYLE_NO_TITLE); | |
} | |
@Override | |
public void onActivityCreated(Bundle arg0) { | |
super.onActivityCreated(arg0); | |
getDialog().getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; | |
getDialog().getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.WRAP_CONTENT); | |
getDialog().getWindow().setGravity(Gravity.BOTTOM); | |
} | |
@Override | |
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { | |
final View v = inflater.inflate(R.layout.main, container, false); | |
cancelTxt = (TextView) v.findViewById(R.id.cancel); | |
cancelTxt.setOnClickListener(this); | |
themesList = (RecyclerView) v.findViewById(R.id.recyclerViewThemes); | |
themes_colors = new int[]{ | |
R.color.theme_pink1, | |
R.color.theme_pink2, | |
R.color.theme_pink3, | |
R.color.theme_blue1, | |
R.color.theme_blue2, | |
R.color.theme_blue3, | |
R.color.theme_red1, | |
R.color.theme_red2, | |
R.color.theme_green1, | |
R.color.theme_green2, | |
R.color.theme_green3, | |
R.color.theme_green4, | |
R.color.theme_purple1, | |
R.color.theme_purple2, | |
R.color.theme_black1, | |
R.color.theme_yellow1, | |
R.color.theme_brown1, | |
R.color.theme_brown2, | |
R.color.theme_green_shade, | |
R.color.theme_grey_shade, | |
R.color.app_color_primary | |
}; | |
adapter = new MyRecycleAdapter(themes_colors, getContext()); | |
LinearLayoutManager horizontalLayoutManagaer = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false); | |
themesList.setLayoutManager(horizontalLayoutManagaer); | |
themesList.setAdapter(adapter); | |
return v; | |
} | |
public class MyRecycleAdapter extends RecyclerView.Adapter<MyRecycleAdapter.MyViewHolder> { | |
private int[] horizontalList; | |
Context context; | |
public MyRecycleAdapter(int[] horizontalList, Context context) { | |
this.horizontalList = horizontalList; | |
this.context = context; | |
} | |
public class MyViewHolder extends RecyclerView.ViewHolder { | |
public ImageView imgView; | |
public MyViewHolder(View view) { | |
super(view); | |
imgView = (ImageView) view.findViewById(R.id.circle_themes); | |
view.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
switch (getPosition()){ | |
case 0: | |
Utility.setTheme(getActivity().getApplicationContext(), 0); | |
recreateActivity(); | |
break; | |
case 1: | |
Utility.setTheme(getActivity().getApplicationContext(), 1); | |
recreateActivity(); | |
break; | |
case 2: | |
Utility.setTheme(getActivity().getApplicationContext(), 2); | |
recreateActivity(); | |
break; | |
case 3: | |
Utility.setTheme(getActivity().getApplicationContext(), 3); | |
recreateActivity(); | |
break; | |
case 4: | |
Utility.setTheme(getActivity().getApplicationContext(), 4); | |
recreateActivity(); | |
break; | |
case 5: | |
Utility.setTheme(getActivity().getApplicationContext(), 5); | |
recreateActivity(); | |
break; | |
case 6: | |
Utility.setTheme(getActivity().getApplicationContext(), 6); | |
recreateActivity(); | |
break; | |
case 7: | |
Utility.setTheme(getActivity().getApplicationContext(), 7); | |
recreateActivity(); | |
break; | |
case 8: | |
Utility.setTheme(getActivity().getApplicationContext(), 8); | |
recreateActivity(); | |
break; | |
case 9: | |
Utility.setTheme(getActivity().getApplicationContext(), 9); | |
recreateActivity(); | |
break; | |
case 10: | |
Utility.setTheme(getActivity().getApplicationContext(), 10); | |
recreateActivity(); | |
break; | |
case 11: | |
Utility.setTheme(getActivity().getApplicationContext(), 11); | |
recreateActivity(); | |
break; | |
case 12: | |
Utility.setTheme(getActivity().getApplicationContext(), 12); | |
recreateActivity(); | |
break; | |
case 13: | |
Utility.setTheme(getActivity().getApplicationContext(), 13); | |
recreateActivity(); | |
break; | |
case 14: | |
Utility.setTheme(getActivity().getApplicationContext(), 14); | |
recreateActivity(); | |
break; | |
case 15: | |
Utility.setTheme(getActivity().getApplicationContext(), 15); | |
recreateActivity(); | |
break; | |
case 16: | |
Utility.setTheme(getActivity().getApplicationContext(), 16); | |
recreateActivity(); | |
break; | |
case 17: | |
Utility.setTheme(getActivity().getApplicationContext(), 17); | |
recreateActivity(); | |
break; | |
case 18: | |
Utility.setTheme(getActivity().getApplicationContext(), 18); | |
recreateActivity(); | |
break; | |
case 19: | |
Utility.setTheme(getActivity().getApplicationContext(), 19); | |
recreateActivity(); | |
break; | |
case 20: | |
Utility.setTheme(getActivity().getApplicationContext(), 20); | |
recreateActivity(); | |
break; | |
} | |
} | |
}); | |
} | |
} | |
@Override | |
public MyRecycleAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.items, parent, false); | |
return new MyRecycleAdapter.MyViewHolder(itemView); | |
} | |
@Override | |
public void onBindViewHolder(final MyRecycleAdapter.MyViewHolder holder, final int position) { | |
holder.imgView.setImageResource(horizontalList[position]); | |
} | |
@Override | |
public int getItemCount() { | |
return horizontalList.length; | |
} | |
} | |
private void recreateActivity() { | |
Intent intent = getActivity().getIntent(); | |
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); | |
getActivity().finish(); | |
getActivity().overridePendingTransition(0, 0); | |
startActivity(intent); | |
getActivity().overridePendingTransition(0, 0); | |
} | |
@Override | |
public void onClick(View v) { | |
int i = v.getId(); | |
if (i == R.id.cancel) { | |
getDialog().dismiss(); | |
} | |
} | |
} |