Posts

Showing posts with the label Android app

How to change status bar color in Sketchware?

Image
Earlier code injection method was required for changing status bar color in sketchware. But now in newer versions of sketchware it can easily be done using add source directly block. To change the status bar color in sketchware project, insert add source directly block in onCreate event in LOGIC of the project, and then write the following code. Window w = this.getWindow(); w.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); w.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); w.setStatusBarColor(Color.parseColor("#000000")); Change the hex color code in last line of the code as per the requirement. It will change color of status bar to the color code provided in the code above. This code has to be used on each screen of the app. Note that this code works in Android versions 5 and above. When the app is used in lower versions, it may crash the app. Therefore, we should use if..else.. to apply this code in compatible ver...

Limiting text length of Edittext in Sketchware

Image
If you want the user to provide only a certain type of text input in the Edittext field, it can easily be done by selecting appropriate option for input_type from text properties. The image below shows the input_type options: However, maxLength or any other option to limit length of input text, is not available in Sketchware. Which means you have to use code blocks in Logic area. To limit the input text length (suppose to 7 characters), in Edittext: edittext1  apply InputFilter to the EditText field. In onCreate event, use an add source directly block and put following codes: InputFilter[] filterArray = new InputFilter[1]; filterArray[0] = new InputFilter.LengthFilter(7); edittext1.setFilters(filterArray); This will limit the input text length to the first 7 characters. With this method, if any extra character is entered at the end, it doesn't appear. If there are 7 characters in the EditText field you cannot add more characters.

Android App: Let people find your shop on map

Image
In android a button or any other event can be set to open a particular location in Google Maps app, with the use of Intent. Suppose you have an Android app for your shop or organization developed in Sketchware, and you want people to reach you. You can provide your address to the app users but a location on maps is always better and preferable. Below is a description of how to link to Google Maps from an android app created in Sketchware. For this Google maps app is a prerequisite and if your user do not have it installed on their device, they may not be able to locate your address on map. Step 1. Download Sketchware App, and create an app for your shop. Insert a button which says 'Locate us' or 'Reach us'. Step 2. Add a new Intent component and name it as share . Step 3. Open Google Maps app. Find Your shop and copy it's coordinates .  Or copy share URL for your address. Step 4. In button onClick event, use blocks as shown below to link your app...

Creating a Quiz Android App

Image
This is a tutorial on creating a quiz in Android. After this tutorial you will be able to create your own Android App with your own quiz. Follow the instructions given below to learn how to create a quiz app in Android. 1. Download Sketchware App for Android devices. 2. Open Sketchware and start a new project. Enter the app name and other details as per your wishes and click save. 3. Now in the View area (main.xml), insert a Scroll(V) and inside that a Linear(V) . Set the width of both the Layouts to match parent and set the padding of Scroll(V) to 0. Also set the background color of Linear(V) to green or a color of your choice, and gravity of Linear(V) to center_horizontal, center_vertical. 4. Now insert 4 button widgets (depends on your requirement), one each for each of the quiz. Each quiz can have several questions. Rename the buttons as Quiz1, Quiz2, Quiz3 and Quiz4 respectively. Now for each of the buttons: increase font size to 18, set margin of each to 8,...

Difference between setVisible_INVISIBLE and setVisible_GONE

Image
Though both setVisible INVISIBLE and setVisible GONE appear to achieve similar tasks, but both are different. With setVisible INVISIBLE object remains on screen but is not seen. Whereas with setVisible GONE, object disappears from screen. Here is an illustration. Suppose there are six imageviews arranged horizontally inside a linear horizontal as shown below. Now in the Logic section, if the fourth image is set VISIBLE and rest of the images are set INVISIBLE, the fourth image will be visible at it's position and rest of the images will disappear, as shown in the image below. Whereas if the fourth image is set VISIBLE and rest of the images are set GONE, all other images will disappear and fourth image will shift to left to occupy the initial available space on left side, as shown in the image below. It appears to be a simple difference but it is important to be aware of this as it can be useful in fixing many bugs in android games and apps.

Sketchware: Stop Keyboard from appearing on startup in Apps with Scroll and Edittext blocks

Image
In Sketchware, if you have a Calculator App or any other app in which you have used an Edittext widget inside a Scroll layout on a page, you will notice that when the page starts, the on-screen keyboard pops up automatically without even touching the Edittext . It happens because in this version of Android, when a view is inflated, the focus sets to the first focusable control by default; and if there is no physical keyboard, the on-screen keyboard will pop up. In the latest version of Sketchware, it is very easy to fix, though it may not be possible in older versions. In order to fix this, in Sketchware App, open your app for editing, go to view manager , choose the page (xml) on which you have to fix the problem of keyboard popping automatically, and set Keyboard state to hidden . Save and run your app, you shall find your problem fixed.