Using Ambilwarna Color Picker in settings to set text color and background color

To add Ambilwarna Color Picker library in Sketchware.

1. In the Sketchware project, in options menu select Local library. Clicking on options menu will display the dexer dialog box as shown in image below. Select D8 or Dx in the dialog.


2. It will show dialog to write library dependency. Write the following dependency - com.github.yukuku:ambilwarna:2.0.1 and click on start. It will search and download the library in Sketchware.

3. Select the Ambilwarna library in Local library.


To create the settings project, follow the steps given below:

1. In main.xml, add a Settings button and and EditText edittext1.

2. In MainActivity, add a Shared preferences component s_pref:s_pref and an Intent component intent.

3. In onStart event, use following codes to retrieve text color and background color from shared preferences and set the text color and background color of edittext1.


4. In the event settings button onClick, use Intent to move to SettingsActivity.

5. In settings.xml, add four buttons textColor, bgColor, button_save, button_reset, and add two linear layouts linear_textcolor and linear_bgcolor.


6. Add a Shared preferences component s_pref:s_pref.

7. Create a more block extra and declare two int color variables using following codes in it.


8. In onCreate event, put following codes to set the background color of linear_textcolor and linear_bgcolor.


9. In button textColor onClick event, use following codes to pick and save text color to shared preferences.



10. In button bgColor onClick event, use following codes to pick and save background color to shared preferences.



11. In button_save onClick event, use finishActivity block.

12. In button_reset onClick event, use following codes to save Black color and transparent color as text color and background color respectively in shared preferences.



13. Save and run the project.

Watch videos below for better understanding.




Comments

Popular posts from this blog

Simple car racing android game in Sketchware

Creating a Drawing View in Sketchware

How to enable upload from webview in Sketchware?

Enable Fullscreen for Youtube videos in WebView

List of Calendar Format symbols valid in Sketchware