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;
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);
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");
Toast.makeText(MainActivity.this,"You clicked this button now",Toast.LENGTH_LONG).show();
txt.setText("Sketch Logic");
}
});
}
}
screenshot
If you get any errors please comment below
Comments
Post a Comment