ButtonShapes/Toast Messages

main.xml
**********
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:text="ButtonShapes/Toast Messages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_gravity="center"
android:layout_marginTop="70dp"
android:gravity="center"/>

<Button
android:id="@+id/btn1"
android:layout_height="wrap_content"
android:layout_width="200dp"
android:text="Button_1"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="@drawable/shape_1"/>

<Button
android:id="@+id/btn2"
android:layout_height="wrap_content"
android:layout_width="200dp"
android:text="Button_2"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="@drawable/shape_2"/>

<Button
android:id="@+id/btn3"
android:layout_height="wrap_content"
android:layout_width="200dp"
android:text="Button_3"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="@drawable/shape_3"/>

<Button
android:id="@+id/btn4"
android:onClick="onClick"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Button_4"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="@drawable/shape_4"/>

</LinearLayout>

______________________

app >>> main >>> res folder >>> ထဲမွာ new folder အသစ္တစ္ခုေဆာက္ၿပီး drawable လို႔အမည္ ေျပာင္းပါ ၿပီးရင္ ေအာက္က code ေတြကုိ အစဥ္လိုက္
shape_1.xml
shape_2.xml
shape_3.xml
shape_4.xml
ဆိုၿပီး ကူးထည့္လိုက္ပါ///

shape_1.xml
*************
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android">

<corners android:radius="1dp"/>

<stroke
android:width="2.5dp"
android:color="#0a0a0a" />

<solid android:color="#FF001B" />

</shape>
_____________________

shape_2.xml
*************
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"

android:shape="rectangle">

<stroke
android:color="#242525"
android:width="2.5dp" />

<corners android:radius="10dp" />

<gradient
android:type="linear"
android:angle="270"
android:startColor="#ff00ff"
android:endColor="#ff001bff" />

</shape>

_______________________

shape_3.xml
*************
<?xml version="1.0" encoding="utf-8"?>

<shape
xmlns:android="http://schemas.android.com/apk/res/android">

<corners android:radius="50dp" />

<stroke
android:width="2.5dp"
android:color="#44433A" />

<solid android:color="#ff001bff" />

</shape>
________________________

shape_4.xml
*************
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">

<item>

<shape android:shape="oval">

<stroke android:color="#616161"
android:width="2.5dp"/>

<solid android:color="#b652c4"/>

<size android:width="100dp"
android:height="100dp"/>

</shape>

</item>
</selector>
________________________

အထက္ပါ code ေတြ ေရးၿပီးရင္ေတာ့ project ကုိ Run လိုက္ပါ Error မရွိပဲ အဆင္ေျပရင္ Button ကုိ ႏိုပ္လိုက္ရင္ Toast message ေလးေတြျပေအာင္ ေအာက္ပါ java code ေလး ေတြ ဆက္ေရးၾကေအာင္ ဗ်ာ ....
________________________

MainActivity.java
*******************
ဒီေနရာမွာ package name ေလးခ်န္ၿပီး က်န္တာ Copy ယူပါ

package km.komyo.bs;

import android.app.*;
import android.os.*;
import android.widget.*;
import android.view.*;

public class MainActivity extends Activity
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

Button btn1=(Button)findViewById(R.id.btn1);
btn1.setOnClickListener(new View.OnClickListener(){

@Override
public void onClick(View v)
{
// TODO: Implement this method
Toast.makeText(getApplicationContext(),"This is button_1",Toast.LENGTH_SHORT).show();

}
});
Button btn2=(Button)findViewById(R.id.btn2);
btn2.setOnClickListener(new View.OnClickListener(){

@Override
public void onClick(View v)
{
// TODO: Implement this method
Toast.makeText(getApplicationContext(),"This is button_2",Toast.LENGTH_SHORT).show();
}
});
Button btn3=(Button)findViewById(R.id.btn3);
btn3.setOnClickListener(new View.OnClickListener(){

@Override
public void onClick(View v)
{
// TODO: Implement this method
Toast.makeText(getApplicationContext(),"This is button_3",Toast.LENGTH_SHORT).show();
}
});
    Button btn4=(Button)findViewById(R.id.btn4);
btn4.setOnClickListener(new View.OnClickListener(){

@Override
public void onClick(View v)
{
// TODO: Implement this method
Toast.makeText(getApplicationContext(),"This is button_4",Toast.LENGTH_SHORT).show();
}
});
}
}

________________________

java လဲကူးထည့္လို႔ error မရွိေတာ့ရင္ Run လိုက္ပါ ၿပီးရင္ button ေလးေတြ ႏိုပ္ၾကည့္ပါ သက္ဆိုင္ရာ Toast message ေလးေတြျပပါလိမ့္မယ္

အဆင္ေျပပါေစ

Happy Coding

ပုဂံသားေလး(ကုိမ်ိဳး)

Beginner ေလးမို႔ Coding အေၾကာင္းေသခ်ာ ရွင္းမျပတက္တဲ့အတြက္ အားလုံးနားလည္ေပးၾကပါ ခင္ဗ် .....


Comments

Popular posts from this blog

♡ မဂၤလာခြန္းဆက္ ♡

《《 ဝမ္းနည္းပါေၾကာင္း 》》