Found 1626 Articles for Android

How to write files to asset folder in android?

Azhar
Updated on 03-Jul-2020 08:41:35

3K+ Views

This example demonstrates how do I write files to asset folder in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 – Create a new Assets folder and write a new text file in it.To write a text file, Right click, select New >> file (Quote.txt)Step 4 − Add the following code to src/MainActivity.javaimport android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import java.io.IOException; import java.io.InputStream; public ... Read More

How to pass a variable from Activity to Fragment in Android?

Azhar
Updated on 03-Jul-2020 08:42:40

4K+ Views

This example demonstrates how do I pass a variable from activity to Fragment in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.                 Step 3 − Add the following code to src/MainActivity.javaimport android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; public class MainActivity extends AppCompatActivity {    EditText editText;    Button button;    @Override    protected void onCreate(Bundle savedInstanceState) {   ... Read More

How to get the Action bar height in android?

Azhar
Updated on 03-Jul-2020 08:44:49

1K+ Views

This example demonstrates how do I get the action bar height in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.                 Step 3 − Add the following code to src/MainActivity.javaimport android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.support.v7.widget.Toolbar;    public class MainActivity extends AppCompatActivity {    Toolbar toolbar;    Button button;    TextView textView;    @Override    protected void onCreate(Bundle savedInstanceState) {   ... Read More

How to convert an image to Base 64 string on Android?

Azhar
Updated on 03-Jul-2020 07:20:49

1K+ Views

This example demonstrates how do I convert an image to Base 64 string on android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 – Copy paste an image in the res/drawable. Example: res/drawable/logo.pngStep 4 − Add the following code to src/MainActivity.javaimport android.annotation.SuppressLint; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Base64; import android.widget.TextView; import java.io.ByteArrayOutputStream; public class MainActivity extends AppCompatActivity {    TextView textView;    String string;    Bitmap ... Read More

How to parse HTML in android?

Azhar
Updated on 03-Jul-2020 07:15:35

2K+ Views

This example demonstrates how do I parse HTML in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 – Add the given dependency in the build.gradle (Module: app)implementation 'org.jsoup:jsoup:1.11.2'Step 4 − Add the following code to src/MainActivity.javaimport android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.TextView; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; import java.io.IOException; public class MainActivity extends AppCompatActivity {    Button button;    TextView textView; ... Read More

How to set the color of a textView span in android?

Azhar
Updated on 03-Jul-2020 07:17:54

819 Views

This example demonstrates how do I set the color of a textView span in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.javaimport android.graphics.Color; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.text.SpannableString; import android.text.Spanned; import android.text.style.ForegroundColorSpan; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    TextView textView;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);     ... Read More

How can I remove a button or make it invisible in Android?

Azhar
Updated on 03-Jul-2020 07:14:01

1K+ Views

This example demonstrates how remove a button or make it invisible in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.               Step 3 − Add the following code to src/MainActivity.javapackage com.example.sample; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.app.Activity; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends AppCompatActivity {    OnClickListener listener1=null;    OnClickListener listener2=null;    Button button1;    Button button2;    @Override    protected void onCreate(Bundle ... Read More

How to create EditText with rounded corners in Android?

Azhar
Updated on 03-Jul-2020 07:00:11

9K+ Views

This example demonstrates how to create EditText with rounded corners in Android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Create a drawable resource file and Add the following code to drawable/et_style.xml         Step 4   − Add the following code to src/MainActivity.javapackage com.example.sample; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.EditText; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       ... Read More

How to display custom view in ActionBar in Android?

Azhar
Updated on 03-Jul-2020 07:01:08

788 Views

This example demonstrates how to display custom view in ActionBar in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to res/layout/custom_action_bar.xml.                                         Step 4 − Add the following code to src/MainActivity.javapackage com.example.sample; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.app.ActionBar; import android.view.View; import ... Read More

How to load and display an image in ImageView on Android App?

Azhar
Updated on 03-Jul-2020 07:01:48

4K+ Views

This example demonstrates how to load and display an image in ImageView on Android App.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MyAndroidAppActivity.javapackage com.example.sample; import android.support.v7.app.AppCompatActivity; import android.app.Activity; import android.os.Bundle; import android.widget.Button; import android.widget.ImageView; import android.view.View; import android.view.View.OnClickListener; public class MyAndroidAppActivity extends AppCompatActivity {    Button button;    ImageView image;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState); ... Read More

Advertisements