Work with Camera in an Android App

Azhar
Updated on 03-Jul-2020 06:39:09

456 Views

This example demonstrates how to work with Camera in an 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/MainActivity.javapackage com.example.myapplication; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.ImageView; public class MainActivity extends AppCompatActivity {    private static final int CAMERA_REQUEST=1888;    ImageView imageView;    @Override   ... Read More

Set Background Drawable Programmatically in Android

Azhar
Updated on 03-Jul-2020 06:36:44

5K+ Views

This example demonstrates how do I set background drawable programmatically 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.RelativeLayout; public class MainActivity extends AppCompatActivity {    Button button;    RelativeLayout relativeLayout;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       relativeLayout = findViewById(R.id.rl);       ... Read More

Change Spinner Text Size and Text Color in Android App

Azhar
Updated on 03-Jul-2020 06:33:51

1K+ Views

This example demonstrates how do I change the spinner textSize and textColor 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.widget.ArrayAdapter; import android.widget.Spinner; public class MainActivity extends AppCompatActivity {    Spinner spinner;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       spinner = findViewById(R.id.spinner);       String[] superHero = ... Read More

Read a File from Assets on Android

Azhar
Updated on 03-Jul-2020 06:33:10

11K+ Views

This example demonstrates how do I read a file from assets 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 – Right click app >> New >> Folder >> Assets folder. Right click on the assets folder, select New >> file (myText.txt) and your text.“Darkness cannot drive out darkness: only light can do that. Hate cannot drive out hate: only love can do that.”Step 4 − Add the following ... Read More

Set Locale Programmatically in Android App

Azhar
Updated on 03-Jul-2020 06:32:23

1K+ Views

This example demonstrates how do I set locale programmatically 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 directory (values-es) and copy the string.xml file into this directory and make the below changes    Sample    Que tengas un buen día Step 4 − Add the following code to src/MainActivity.javaimport android.content.res.Configuration; import android.content.res.Resources; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.DisplayMetrics; import java.util.Locale; public class MainActivity extends AppCompatActivity {    @Override ... Read More

Get Height and Width of Android ImageView Widget

Azhar
Updated on 03-Jul-2020 06:29:21

2K+ Views

This example demonstrates how do I get the height and width of the android.widget.ImageView 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.ImageView; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    TextView textView;    Button button;    ImageView imageView;    @Override    protected void onCreate(Bundle savedInstanceState) {   ... Read More

Load ImageView by URL in Android

Azhar
Updated on 03-Jul-2020 06:26:41

7K+ Views

This example demonstrates how to load an ImageView by URL 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.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.AsyncTask; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.widget.ImageView; import android.widget.Toast; import java.io.InputStream; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);     ... Read More

Change Android Overflow Menu Icon Programmatically

Azhar
Updated on 03-Jul-2020 06:24:42

2K+ Views

This example demonstrates how do I change android overflow menu icon programmatically.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.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    Toolbar toolbar;    @Override    public void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       toolbar ... Read More

Pass Drawable Between Activities in Android

Azhar
Updated on 03-Jul-2020 06:23:20

851 Views

This example demonstrates how do I pass drawable between activities 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.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity {    Button button;    @Override    public void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       button = findViewById(R.id.button);       button.setOnClickListener(new View.OnClickListener() { ... Read More

Add a Line Break in an Android TextView

Azhar
Updated on 03-Jul-2020 06:22:30

7K+ Views

This example demonstrates how do I add a line break in an android textView.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.widget.TextView; public class MainActivity extends AppCompatActivity {    TextView textView;    @Override    public void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       textView = findViewById(R.id.textView);       textView.setTextColor(Color.RED);    } ... Read More

Advertisements