How to create a button that open a new activity in android :
Java:
Java:
rotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); Button start = (Button)findViewById(R.id.Strat); start.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(MainActivity.this,dept.class); startActivity(i); } });
XML:
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="vertical">
<Button android:id="@+id/Strat" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="70dp" android:background="@drawable/start" android:paddingLeft="125dp" android:paddingRight="125dp" android:textAlignment="center" android:textColor="@color/colorewhite" android:textSize="25sp" /> </LinearLayout>
No comments:
Post a Comment