Android App Development || Make wallpaper app using Button - Passionate Geekz

Breaking

Where you can unleash your inner geek.

Thursday, 27 June 2019

Android App Development || Make wallpaper app using Button

This Guide helps you to built your own wallpaper app using a button . in this you will not learn json scripts or java scripts . you need some wallpaper’s

In this guide or upcoming i will not show you how to setup and all stuff . i am pretending that you have downloaded the android studio and ready to start with your first android app.

  • Create android project and named it as Change_Activity .
  • Choose target android versions  and add an activity
  • Always Generate layout file This habit will help  you in  future

Using previous Examples

Now you know how to create multiple activities .

In this tutorial I will make wallpaper app having 5 different wallpaper’s we will alos learn how to set as wallpaper programmatically

Lets Start

Create 5 Empty or Basic Activities With Their Respective layouts just like below image

Now add a image view in your activity_main.xml also add a Button which helps you Change or move from one wallpaper to another

Here am Using FloatingAction button to Change or move from one wallpaper to another

 

Your code will look like this:-

Add Image View in your  Content_main.xml


android:id="@+id/im1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/d1"
tools:layout_editor_absoluteX="-16dp"
tools:layout_editor_absoluteY="-84dp"

Add FloatingActionButton in your  Activity_main.xml



<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_input_add"
/>

Now Create Multiple Activities Right Click On java Folder Select New Scroll To Activity and Create Multiple  Empty Activity or Any using Same Methods .

 



If youe are using FloatinButton to Change Activities just like i did then add below method in your MainActivity.java

FloatingActionButton fab = findViewById(R.id.fab);fab.setOnClickListener(new View.OnClickListener() {    @Override    public void onClick(View view) {        Intent i = new Intent(Main4Activity.this,Main2Activity.class);        startActivity( i);

Or you can add a Button to Change Activites using below code  in your MainActivity,java

Private Button b1;

Button b1 = findViewById(R.id.button);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(Main4Activity.this,Main2Activity.class);
startActivity( i);

Now you can build your app it will Change the wallpaper by pressing Button

now the main part use image view as your wallpaper .

use below code in your MainActivity.java  it will helps you to replace your Current wallpaper with the imageView that you have add in your Respective layout files


FloatingActionButton fab = findViewById(R.id.fab);fab.setOnClickListener(new View.OnClickListener() {    @Override    public void onClick(View view) {        Intent i = new Intent( MainActivity.this , Main2Activity.class);        startActivity(i);        FloatingActionButton fab1= findViewById(R.id.fab1);        fab1.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                setwallpaper();            }            private void  setwallpaper(){                Bitmap b = BitmapFactory.decodeResource(getResources(),R.drawable.d1);                WallpaperManager wm= WallpaperManager.getInstance(getApplicationContext());                try {                    wm.setBitmap(b);                    Toast.makeText(MainActivity.this, "Set succesful", Toast.LENGTH_SHORT).show();                } catch (IOException e)                {                    Toast.makeText(MainActivity.this, " Eroor ", Toast.LENGTH_SHORT).show();                }            }

 This is it if you faced any problem feel free to comment below Thanks

 

No comments:

Post a Comment