Skip to main content

Working With Android Studio

Working With Android Studio  

 [# 1]



Video Link:       https://youtu.be/9zcki3STZ00    



Please Watch The Above Video If You haven't Watched It Already



1)  Open Android Studio and create a new project .

2) Give a name for your application and also set the package name.



3) Set The API level





4) Choose an Activity




5) Set the Activity Name and Layout Name





6) Click On Finish. Your project will be ready in few minutes.


7) Navigate to the layout directory and open activity_main.xml file


8)The code used in the video is given here

<?xml version="1.0" encoding="utf-8"?><LinearLayout     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:orientation="vertical"     tools:context=".MainActivity">


<Button     android:id="@+id/btn1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="Display My name"     android:textAllCaps="false"/>


<TextView     android:id="@+id/txt1"     android:textStyle="bold"     android:textSize="24sp"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="Hello World!" />

</LinearLayout>




Screenshot 




9) Next Naviagte to MainActivity.java file. The code used is given below

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;


public class MainActivity extends AppCompatActivity {


private Button btn;
private TextView txt;


    @Override 

       protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);


       btn=(Button)findViewById(R.id.btn1);
       txt=(TextView)findViewById(R.id.txt1);



    btn.setOnClickListener(new View.OnClickListener() {
        @Override 
          public void onClick(View v) {
          Toast.makeText(MainActivity.this,"You clicked this button            now",Toast.LENGTH_LONG).show();
          txt.setText("Sketch Logic");

      }

    });

   }


  }




screenshot





10) Now Run Your App Test the app on your real device or emulator.
If you get any errors please comment below










Comments

Did you like this tutorial ?

Popular posts from this blog

Add Edittext Inside Dialog Box

Add Edittext Inside Dialog Box




If you haven`t yet watched the video...Watch it right now!!!


The code used in the above video is available here.
final EditText edittext1= new EditText(MainActivity.this); LinearLayout.LayoutParams lpar = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); edittext1.setLayoutParams(lpar); dialog.setView(edittext1);







textview1.setText(edittext1.getText());






Create Custom Popup Window using Sketchware

Create Custom Popup Window using Sketchware


Refer the video below if  you get stuck. 

1) Add a custom view named window.You can name it according to your wish. 
2)Design your popup window. 
2) Now, In the logic section,In OnCLick event of button.Add the following  code
Create a view
View popupView = getLayoutInflater().inflate(R.layout.window, null);
Popup window 

final PopupWindow popup = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
Initialize 
Button b1 = popupView.findViewById(R.id.button1); Button b2 = popupView.findViewById(R.id.button2);
OnClickListeners
b1.setOnClickListener(new OnClickListener() { public void onClick(View view) { //below code will dismiss the popup window popup.dismiss(); } });
b2.setOnClickListener(new OnClickListener() { public void onClick(View view) {
popup.dismiss(); } });
Show the popup window 
popup.showAtLocation(popupView, Gravity.CENTER, 0, 0);




Add Swipe To Refresh Feature To Your App using Android Studio

Add Swipe To Refresh Feature To Your App Using Android Studio


If you haven't watched the video watch it now!


Source Code
Android Manifest.xml



<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="swiperefresh.com.swipetorefresh"> <uses-permission android:name="android.permission.INTERNET" /> <applicationandroid:allowBackup="true"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:roundIcon="@mipmap/ic_launcher_round"android:supportsRtl="true"android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>…