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
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
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
The HTML DOM input month autofocus property returns and modify whether the input month field should get focused or not when page load.SyntaxFollowing is the syntax −Returning autofocusobject.autofocusModifying autofocusobject.autofocus = true | falseExampleLet us see an example of HTML DOM input month autofocus property − Live Demo HTML DOM autofocus property body{ text-align:center; } p{ font-size:1.5rem; color:#ff8741; } input{} button{ background-color:#db133a; color:#fff; padding:8px; border:none; width:120px; ... Read More
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
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
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
This example demonstrates how do I request Location permission 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.Manifest; import android.content.pm.PackageManager; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.Toast; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if ... Read More
The map is basically a collection of elements where each element is stored as a Key, value pair. It can hold both objects and primitive values as either a key or a value. When we iterate over the map object it returns the key, value pair in the same order as inserted. The map has provided a method called map.clear() to remove the values inside a map. This method will remove every key/value pair and make the map totally empty.syntaxmap.clear(obj);map.obj() takes an object as a parameter and removes each and every value so as to make it empty.Example-1In the following example, a map is created ... Read More
The header function in PHP can be used to redirect the user from one page to another. It is an in-built function that sends raw HTTP header to the destination (client).Syntax of header functionheader( $header_value, $replace_value, $http_response_code)Following are the parameters −The ‘header_value’ in the function is used to store the header string.The ‘replace_value’ parameter stores the value that needs to be replaced.The ‘response_code’ is used to store the HTTP response code.ExampleThe website to which the page needs to be redirected is specified in the header function.