1 Android studio qanday dastur tushuntiring Android Studio
Download 17.79 Kb.
|
1 2
Bog'liq1 Android studio qanday dastur tushuntiring
Java konstruktor obyekt yaratish vaqtida chaqiriladi Javada konstruktor yaratish qoidalari: Konstruktor klass nomi bilan o'xshash bo'lishi kerak 1 2 misol onclick package com.baxodirdavirov.lesson_1; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; 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); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { changetitle(); } }); } public void changetitle(){ setTitle("Changetitle"); } } 3 misol package com.example.widgets; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.CheckBox; import android.widget.Toast; public class CheckBoxExample extends AppCompatActivity { CheckBox c1,c2,c3; Button b1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_check_box_example); c1=(CheckBox)findViewById(R.id.check1); c2=(CheckBox)findViewById(R.id.check2); c3=(CheckBox)findViewById(R.id.check3); b1=(Button)findViewById(R.id.submit); b1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (c1.isChecked()&&c2.isChecked()&&c3.isChecked()) { Toast.makeText(getApplicationContext(),""+c1.getText()+" , "+c2.getText()+" , "+c3.getText(),Toast.LENGTH_SHORT).show(); }else if (c1.isChecked()&&c2.isChecked()){ Toast.makeText(getApplicationContext(),""+c1.getText()+" , "+c2.getText(),Toast.LENGTH_SHORT).show(); }else if (c1.isChecked()&&c3.isChecked()){ Toast.makeText(getApplicationContext(),""+c1.getText()+" , "+c3.getText(),Toast.LENGTH_SHORT).show(); }else if (c2.isChecked()&&c3.isChecked()){ Toast.makeText(getApplicationContext(),""+c2.getText()+" , "+c3.getText(),Toast.LENGTH_SHORT).show(); }else if (c1.isChecked()){ Toast.makeText(getApplicationContext(),""+c1.getText(),Toast.LENGTH_SHORT).show(); }else if (c2.isChecked()){ Toast.makeText(getApplicationContext(),""+c2.getText(),Toast.LENGTH_SHORT).show(); }else if (c3.isChecked()){ Toast.makeText(getApplicationContext(),""+c3.getText(),Toast.LENGTH_SHORT).show(); } } }); } } 4 misol chekbox android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".CheckBoxExample" android:orientation="vertical" android:gravity="center"> android:layout_height="wrap_content" android:text="Fruits" android:textSize="20sp" android:textColor="@color/colorOrange"/> android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Apple" android:textColor="@color/colorAccent"/> android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Orange" android:textColor="@color/colorPrimary"/> android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Mango" android:textColor="@color/colorBlue" android:layout_marginBottom="20dp"/> android:id="@+id/submit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Submit" android:textColor="@color/colorWhite" android:background="@color/colorPrimary"/> 5 misol checbox package com.example.widgets; import android.graphics.Color; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.LinearLayout; import android.widget.Switch; import android.widget.Toast; public class SwitchExample extends AppCompatActivity { LinearLayout linearLayout; Switch aSwitch; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_switch_example); linearLayout=(LinearLayout)findViewById(R.id.linearLayout); aSwitch=(Switch)findViewById(R.id.switchbutton); aSwitch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (aSwitch.isChecked()){ linearLayout.setBackgroundColor(Color.CYAN); Toast.makeText(getApplicationContext(),"Switch is clicked & background is cyan",Toast.LENGTH_SHORT).show(); }else{ linearLayout.setBackgroundColor(Color.RED); Toast.makeText(getApplicationContext(),"Switch is clicked & background is red",Toast.LENGTH_SHORT).show(); } } }); } } 6 misol paketi com . misol . vidjetlar ; androidni import qilish . grafika . rang ; androidx import . appcompat . ilova . AppCompatActivity ; androidni import qilish . os . to'plam ; androidni import qilish . ko'rish . Ko'rish ; androidni import qilish . vidjet . LinearLayout ; androidni import qilish . vidjet . Switch ; androidni import qilish . vidjet . tushdi ; umumiy sinf SwitchExample AppCompatActivity -ni kengaytiradi { LinearLayout linearLayout ; aSwitch ga o'tish ; @ bekor qilish himoyalangan void onCreate ( to'plam savedInstanceState ) { super . onCreate ( savedInstanceState ); setContentView ( R. layout . Activity_switch_example ) ; linearLayout =( LinearLayout ) findViewById ( R . id . linearLayout ); aSwitch =( Switch ) findViewById ( R . id . switch tugmasi ); aSwitch . setOnClickListener ( yangi ko'rish . OnClickListener () { @ bekor qilish public void onClick ( View v ) { agar ( aSwitch . isChecked ()){ linearLayout . setBackgroundColor ( Rang . CYAN ); Tost . makeText ( getApplicationContext (), "Switch bosilgan va fon ko'k rangda" , Toast . LENGTH_SHORT ). ko'rsatish (); } boshqa { linearLayout . setBackgroundColor ( Rang . RED ); Tost . makeText ( getApplicationContext (), "Switch bosildi va fon qizil" , Toast . LENGTH_SHORT ). ko'rsatish (); } } }); } } 7 misol progrebar xml versiyasi = " 1.0 " kodlash = " utf-8 " ?> < LinearLayout xmlns : android = " http://schemas.android.com/apk/res/android " xmlns:tools= " http://schemas.android.com/tools " android:layout_width= " match_parent " android:layout_height= " match_parent " asboblar:kontekst= " .ProgressBarExample " android: gravitatsiya = " markaz " android:orientation= " vertikal " android:padding= " 16dp " > < TextView android: id = " @+id/matn " android:layout_width= " wrap_content " android:layout_height= " wrap_content " android:text= " Ishga tushirish tugmasini bosing " android:layout_marginBottom= " 20dp " /> < ProgressBar 19 android : id = " @+id/progress " android:layout_width= " match_parent " android:layout_height= " wrap_content " android:layout_marginBottom= " 24dp " style= " @style/Widget.AppCompat.ProgressBar.Horizontal " android: max= " 100 " /> < Android tugmasi : id = " @+id/start " android:layout_width= " wrap_content " android:layout_height= " wrap_content " android:text= " Boshlash " android:textColor= " @color/colorWhite " android: fon = " @color/colorOrange " /> LinearLayout > Download 17.79 Kb. Do'stlaringiz bilan baham: |
1 2
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling