Found 1631 Articles for Android

How to programmatically turn on Wifi on Android device?

Azhar
Updated on 01-Jul-2020 08:11:49

1K+ Views

This example demonstrates how do I programmatically turn on wifi in android device.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.Context; import android.net.wifi.WifiManager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    private WifiManager wifiManager;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       ... Read More

How to change the text color of Menu item in Android?

Azhar
Updated on 01-Jul-2020 07:42:13

5K+ Views

This example demonstrates how do I change the text color of the menu item 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 on res/drawable, create any Vector Asset (Example: ic_icon.xml)Step 4 – Right-click on res, select New -> Android Resource Directory – menu.Step 5 – Right Click on res/menu and create a new Menu Resource file and add the following code in res/menu/sample_menu.xml     ... Read More

How to get Spinner Value in android?

Azhar
Updated on 03-Jul-2020 08:37:09

4K+ Views

This example demonstrates how do I get spinner value 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 – Open res/values/strings.xml and add the following code    Sample           crane       Cuckoo       Pigeon       Pigeon       Eagle       Owl       Vulture       WoodPecker     ... Read More

How to programmatically set drawableLeft on Android button?

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

5K+ Views

This example demonstrates how do I programmatically set drawableleft 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.drawable.Drawable; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.Button; public class MainActivity extends AppCompatActivity {    Button button;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       button = findViewById(R.id.button);       Drawable ... Read More

How to lock screen orientation on all android devices programmatically?

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

1K+ Views

This example demonstrates how do I lock screen orientation on all android devices 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.content.pm.ActivityInfo; import android.content.res.Configuration; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       int currentOrientation = getResources().getConfiguration().orientation;     ... Read More

How to set margin of ImageView using code in Android?

Azhar
Updated on 01-Jul-2020 07:49:26

915 Views

This example demonstrates how do I set margin of ImageView using code 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 – Copy an image file and paste in the res/drawableStep 4 − Add the following code to src/MainActivity.javaimport android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.ImageView; import android.widget.RelativeLayout; public class MainActivity extends AppCompatActivity {    ImageView imageView;    @Override    protected void onCreate(Bundle savedInstanceState) {   ... Read More

How can I create custom button in Android using XML Styles?

Azhar
Updated on 01-Jul-2020 07:38:38

3K+ Views

This example demonstrates how do I create custom button in Android using XML Styles.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 on res/drawable, Select new → Drawable resource file and add the following code in custom_dialog.xml         Step 4 – Right Click on res/drawable, Select new → Drawable resource file and add the following ... Read More

How to get a working vertical seekBar in Android?

Azhar
Updated on 01-Jul-2020 07:39:32

1K+ Views

This example demonstrates how do I get a working vertical seekBar 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.SeekBar; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    SeekBar seekBar;    TextView textView;    int min = 0, max = 100, current = 50;    @Override    protected ... Read More

How to add footer in Android ListView?

Azhar
Updated on 03-Jul-2020 08:30:11

767 Views

This example demonstrates how do I add footer in Android ListView.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 layout file.xml and name it as listView_footer.xml and add the following code −         Step 4 − Add the following code to src/MainActivity.javaimport java.util.ArrayList; import java.util.Arrays; import java.util.List; import android.app.Activity; import android.os.Bundle; import android.view.LayoutInflater; import android.view.ViewGroup; import android.widget.ArrayAdapter; import ... Read More

Dynamically add elements in ListView in android?

Azhar
Updated on 03-Jul-2020 08:31:00

3K+ Views

This example demonstrates how do I dynamically add elements in ListView 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 java.util.ArrayList; import java.util.Arrays; import java.util.List; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; public class MainActivity extends Activity {    ListView listview;    Button addButton; ... Read More

Advertisements