Posts

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.

Request Result Using startActivityForResult and Listen to It in onActivityResult

Let us say we have two activities (First Activity and Second Activity) in our Android application then startActivityForResult() is used by the First Activity when it expects a result from the Second Activity and onActivityResult() is used to read the returned result from the Second Activity.
In simple terms, we can send information to the top activity in the back stack.
From our First Activity, start the Second Activity with a request code.
// Open the second activity startActivityForResult( Intent(context, SecondActivity::class.java), REQUEST_CODE_FETCH_RESULT )
This opens the Second Activity. When we are done with the Second Activity and want to pass the data back to the First Activity, we call setResult and close our Second Activity.
// Set the result in the Second Activity val intent = Intent().apply { // Intent extras putExtra(BUNDLE_EXTRA_ACTIVITY_FINISHED, true) } activity?.run { // Set the result setResult(RESULT_OK, intent) /…

How to Create an Emulator in Android Studio

Image
In this article, we will take a look at how to create an emulator in Android Studio.
First, open Android Studio to create a project or open an existing project. Now, Click on the Tools in the top menu and then on AVD Manager.

This opens the Android Virtual Device Manager where we can create our emulators.


Start the creation of the emulator by clicking on the Create Virtual Device button. It opens a new screen where we select the device hardware.


In addition to the available hardware profiles, we can import an existing profile or create new hardware by clicking on the options at the bottom left.


Click Next after selecting the hardware profile. Now we are asked to select the OS Version. Select the preferred one and download it if necessary. After that, click Next.




Verify the configuration of the selected hardware. If we want to tweak more than the AVD name then in the advanced settings we can change the number of cores, RAM, internal Storage space, external storage space and more.


Fina…