Posts

Add a Module to an Android Project

Image
In this article, we will take a look at creating a new module and adding it to our project. First, create a new project or open an existing project.
Right-click or tap with two fingers on the app module or the project. This opens an options menu where we need to click on New and then on Module option in order to start the process of creating a module.

The other way to start the module creation process is by clicking on the File menu in the top bar, hovering over New option and then clicking on the New Module option.

Clicking on the New Module option opens a window where we need to select the Module type. Select the preferred module type based on feature development. For example, we can select the Android Library type if we are building a library, the Android TV Module if we want to expand our app to be available on TV, the Dynamic Feature Module if we want the feature to be available upon user request and not bloat the app size when packaging.

In the next window, we have to enter the name…

Create Assets Folder, Add Files and Read Data From It

Image
Sometimes, we need to read the data stored in the files during runtime and want to make sure the data is not tampered by the Android build system. In this article, we will take a look at how to create the assets folder using Android Studio and read the stored data from it.
First, Right-click on the module name or the package name. This opens an option window where we need to select the Assets Folder option by hovering over New and then on the Folder option.

Now, we will see a window where we change the folder location and the source set. Change the values if necessary otherwise keep the defaults and click Finish. It may trigger a Gradle Sync.

Irrespective of the sync, the Assets folder is created and is visible in the module. Now, Right-click on the Assets folder and click on the File option by hovering over the New option.

Enter the name of the file name and click Enter to create the file.

The file with the name user_details.json is created under the assets folder. Add some JSON data to t…

Create Multiple YouTube Channels

Image
In this article, we will take a look at creating multiple YouTube channels under the same email address instead of using multiple email addresses for multiple YouTube channels.
1. Go to the Youtube account settings page.
2. Find and click on the Add or manage your channel(s) option under the Your YouTube Channel section.

3. In the next page, we are shown the list of existing channels and an add button to create another channel. Click Create a new channel card.

4. In the next page, enter the channel name (brand name) and click the Create button.

5. After multiple redirects, we are taken to the home page of our channel where we can start uploading our videos to the new channel.

Add Options Menu to Activity and Fragment

Image
Options Menu contains a set of primary menu items that are accessible to the user. In this article, we will take a look at how to implement the options menu in an Android Activity or a Fragment.

Right click on the res directory in Android Studio and select Android Resource File option. It opens the Resource File creation modal where we need to enter the file name and select Resource Type as Menu.


Clicking on OK button creates main_menu.xml under menu directory. Now add the following items to the XML file. <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/search" android:icon="@drawable/ic_search_white" android:orderInCategory="100" android:title="@string/action_title_search" app:actionViewClass="androidx.appcompat.widget.SearchView" app:showAsAction="ifRoom&qu…

Change Snackbar Position When Bottom App Bar or Bottom Navigation View Is Present

Image
The SnackBar is mainly used to provide feedback to the user and it is shown at the bottom of the screen. This UI element is used alongside Toast or as a replacement in some application.
We typically show snack message as follows.
// Show snack message Snackbar.make(binding.coordinatorLayout, message, LENGTH_SHORT) .show();
This works well as long as the screen does not contain the Bottom App Bar or the Bottom Navigation View. When we have the specified elements the Snack Message overlaps on the Bottom App Bar or ends up behind the Bottom Navigation View.

This behavior is shown in the images below.

To avoid such behavior we need to use setAnchorView method and pass id of a view. The Snack Message is shown on top of the view element with the specified id.
// Show snack message Snackbar.make(binding.coordinatorLayout, message, LENGTH_SHORT) .setAnchorView(binding.fab) .show();

Similarly, when Bottom Navigation View or Floating Action Button id is passed to setAncho…

Material Chip in Android

Image
Chip, a Material Design Component is used as an action like setting an alarm or a choice like selecting a gender or to filter items like dress types or input types like hints.
Similar to RadioGroup, if we want to create a group of chips with single selection behavior we use ChipGroup and set singleSelection variable to true.


<com.google.android.material.chip.ChipGroup android:id="@+id/genderChip" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="@dimen/edit_text_horizontal_margin" android:layout_marginTop="@dimen/edit_text_vertical_margin" android:layout_marginEnd="@dimen/edit_text_horizontal_margin" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/fullNameTextInputLayout" app:singleSelection="true"> <com.google.a…

Create Github Repository

Image
Github is a freemium cloud-hosted version control system where the developers can host unlimited public and private repositories for free.
Follow the below steps to create a new repository on Github.
1. The very first thing to do is go to the link https://github.com/new. It provides the fields to enter in order to create our repository.

2. Enter the Repository name and Description for our project.
3. We can select our project to be a Public project or restrict it to be Private.
4. In addition to that, we can create our project with a default README file by checking the box, gitignore file by selecting the language and a license from the dropdown.
5. Finally, click on the Create repository button.
This creates a Private project that a link https://github.com/gSrikar/Android-Studio-Settings.