Tag: mobile development

  • Android: underline text in your app

    When I need to underline text in an app that I’m developing, I like doing it programmatically. The code is in the Java file, not in the XML.

    Maybe we should make a function for this where we pass the ID of the TextView whose content we’d like to underline.

    Disadvantages in this method:

    • It’s done in the Java file, not in UI files such as XML. It makes more sense to add codes for styling in XML files to me.
    • This underlines all text in the TextView. What if we need to underline only one text in a paragraph?

    If you have any suggestion, feel free to comment. 🙂

    // EDIT:

    Here’s a method I prepared to make underlining TextView values easier:

    public void setTextViewUnderline(TextView myTextView){
    String htmlString = “” + myTextView.getText() + ““;
    myTextView.setText(Html.fromHtml(htmlString));
    }

  • Android: dimensions cheat sheets for graphic designers AND developers

    Just sharing the link to a “cheat sheet” that I found:

    Android Cheatsheet for Graphic Designers

    I think that this resource should have been said to be for developers too, because developers need to know about dimensions of graphics in the Android apps they develop.

  • Android transparent overlay without View

    We’re not going to use ViewOverlay here. We’ll use Dialog instead.

    The overlay does not show on button click. What I did was let the overlay appear when the activity is loaded.

    First, create the XML file for the contents of that dialog overlay.

    \app\src\main\res\layout\popup_content.xml

    Then add the following code into your activity’s Java file. Please edit as needed in your project.

    Notes:
    You might need to add lines of “import” codes yourself for the classes I used.
    You might need to fill in missing @color and @dimen values yourself.

    app\src\main\java\com\yourpackagename\yourappname\activities\MainActivity.java

  • Android app dev: background image sizes for different screen sizes

    Here are the recommended background image sizes in pixels for Android app development:

    xxxhdpi: 1280×1920 px
    xxhdpi: 960×1600 px
    xhdpi: 640×960 px
    hdpi: 480×800 px
    mdpi: 320×480 px
    ldpi: 240×320 px

    …as suggested in this StackOverflow page: Android: Background Image Size (in Pixel) which Support All Devices

  • Android ImageView has unwanted padding: layout troubleshooting


    If you use ImageView in your android app layout and you get that unwanted padding around the image, here’s an Android XML attribute that helped me solved the layout issue:

    Add android:adjustViewBounds="true" attribute to your ImageView XML tag and you’ll probably see the unwanted padding go away.

    According to the ImageView docs:

    android:adjustViewBounds

    Set this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable.

    You might also want to check the related Java method: setAdjustViewBounds(boolean)

  • Android app dev: image sizes for variety of screen sizes

    As a mobile app developer, we need to consider various screen sizes for a wide range of Android devices.

    Here’s a quick note of recommended image sizes for Android app icons:

    36×36 for low-density (LDPI)
    48×48 for medium-density (MDPI)
    72×72 for high-density (HDPI)
    96×96 for extra high-density (XHDPI)
    180×180 for extra extra high-density (XXHDPI)
    192×192 for extra extra extra highv-density (XXXHDPI)

    Image Scaling

    Source: Units and measurements – Layout – Google design guidelines

    Images can be scaled to look the same across different screen resolutions by using these ratios:

    Screen resolution dpi Pixel ratio Image size (pixels)
    xxxhdpi 640 4.0 400 x 400
    xxhdpi 480 3.0 300 x 300
    xhdpi 320 2.0 200 x 200
    hdpi 240 1.5 150 x 150
    mdpi 160 1.0 100 x 100

    For our reference. 🙂

    You may read more about Supporting Multiple Devices.

    I also want to share MakeAppIcon. Use that online tool to quickly generate resized images for various Android screen sizes for you.

  • Android: 2-dimensional List String (List of List)

    For a web developer who used mostly PHP and JavaScript for several years, plunging into Java can be challenging especially when it comes to data types.

    PHP and JavaScript are loosely typed languages, while Java is strict about types.

    I was told that in Android, List<String> is very commonly used, even more than arrays. And now I’ve come to the point when I need to use a 2-dimensional List<String>.

    Here’s a sample code:

    Output of System.outprintln(Arrays.deepToString(ls.toArray())); is this:

    The output of Log.d("serialized", listOfList.toString()); is this:

  • Android confirm dialog box with OK and Cancel button

    Android confirm dialog box with OK and Cancel button

    This will probably be one of the Android code snippets that I will need to go back to from time to time.

    I’m sharing the codes we need to show an Android confirm dialog to prompt the user to click “yes” or “no”, or in my case, “OK” or “Cancel”.

    The following code for Android confirm dialog is in my MainActivity.java file:

    (more…)

  • Android Studio dark theme (change into Darcula theme)

    Android Studio dark theme (change into Darcula theme)

    You might feel more comfortable with a dark theme in Android Studio, but the default theme is light in color.

    Default light theme in Android Studio
    Default light theme in Android Studio

    I’m one of the developers who always code in dark screens since it’s less tiring to the eyes.

    Android Studio dark theme
    Android Studio dark theme — Darcula

    If you’re like me who prefers dark themes while coding, then I’ll show you how to change into a dark theme called Darcula in Android Studio here. (more…)

  • How to change app name in Android Studio

    How to change app name in Android Studio

    I’m trying to learn how to build a simple app in Android just to satisfy my curiosity. This will also be a very handy skill because I use Android phones often, and there are times that the apps I download from Google Play Store lack features that I need.

    This will be a very simple guide on how to change app name in Android Studio, something that most beginners in Android development probably want to know.

    It is assumed in this guide that you have prior knowledge in coding.

    The app name that I’m referring to is the one that says “My Application”, as marked on the image below:

    How to change app name in Android Studio

    To change that, go to your Project and find the app folder. Under app, find AndroidManifest.xml and edit android:label="My Application", replacing “My Application” with the name you’d like to use.

    Refer to the image below:

    android-studio-android-manifest

    Your changed app name should be reflected in the live preview now, if you have it activated. If you don’t have live preview yet, check this out: Where is Android Studio layout preview?

    Updates…

    How to rename project folders of Android Studio

    You may also want to change the name of your Android app’s folder. Check this folder, it’s probably where your Android project folder is located — C:\Users\catkeng\AndroidStudioProjects\

    How to rename package in Android Studio

    Right-click on your package name in the Project tree. It’s probably under app->java. Then choose “Refactor”, then choose “Rename”. Take note that you’ll see “Rename package” and “Rename folders” button here — you might need to go back to this screen later to click “Rename folders”. For now, click the “Rename package” button. Type the new name that you want to use, then click “Refactor”. If that hasn’t changed all package name instances for you, follow the same steps until you can click “Rename folders” button too. That should do it!