Skip to main content

Posts

Showing posts from September, 2015

android - How to save image to file in external storage

activity_main.xml <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#F8F8FF" android:padding="16dp" tools:context=".MainActivity"> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Save Image To External Storage" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <ImageView android:id="@+id/ivSource" android:layout_width="0dp" android:layout_height=...

android - How to save an image to gallery

activity_main.xml <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#F8F8FF" android:padding="16dp" tools:context=".MainActivity"> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Save Image To Gallery" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <ImageView android:id="@+id/ivSource" android:layout_width="0dp" android:layout_height="200...

android - How to take ScreenShot programmatically

activity_main.xml <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="24dp" android:id="@+id/rootLayout" tools:context=".MainActivity" android:background="#DCDCDC"> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Take ScreenShot" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <ImageView android:id="@+id/imageView" android:layout_width="0dp" ...

android - How to change ActionBar title programmatically

MainActivity.java package com.cfsuman.androidtutorials; import android.os.Bundle; import android.widget.Button; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Get the widgets reference from XML layout Button button = findViewById(R.id.button); // Set the button click listener button.setOnClickListener(view -> { // Get the ActionBar ActionBar actionBar = getSupportActionBar(); // Change the ActionBar title text assert actionBar != null; actionBar.setTitle("Updated ActionBar Title"); }); } } activity_main.xml <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.Const...