AIDE Tutorial - 8 Toast Gravity
Add a button on XML
<Button
android:onClick="Click1"
android:text="Click Me"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Import these on Java
import android.view.View;
import android.widget.Toast;
Add after R.layout.main
public void Click1 (View view){
Toast aaa = Toast.makeText(
getApplicationContext(),
"you clicked",
Toast.LENGTH_SHORT
);
aaa.setGravity(Gravity.BOTTOM,0,0);
aaa.show();
}
For center change BOTTOM to CENTER
For top change BOTTOM to TOP
Fill the horizontal
aaa.setGravity(Gravity.TOP|Gravity.FILL_HORIZONTAL,0,0);
0 comments:
Post a Comment