Android Project:UI Control:
Android
Project:UI Control
>>>Create
a New Project Name UI_Control
>>>
Create a Class name MainActivity.java than Paste My Code
package
com.sattar.uicontroldemo
import
android.app.Activity;
import
android.os.Bundle;
import
android.view.View;
import android.view.View.OnClickListener;
import
android.widget.Button;
import
android.widget.Toast;
public
class MainActivity extends Activity implements OnClickListener {
Button btnTest;
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnTest=(Button)
findViewById(R.id.etTestBtn);
btnTest.setOnClickListener(this);
}
public void test(View v) {
Toast.makeText(getApplicationContext(),
"test button clicked",
Toast.LENGTH_LONG).show();
}
@Override
public void onClick(View arg0) {
Toast.makeText(getApplicationContext(),
"test button clicked",
Toast.LENGTH_LONG).show();
}
public void normalPressed(View v) {
Toast.makeText(getApplicationContext(),
"Normal button clicked",
Toast.LENGTH_LONG).show();
}
}
>>>
Create an Xml File name activity_main
<RelativeLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="100dp"
android:layout_marginTop="96dp"
android:orientation="vertical" >
</LinearLayout>
<Button
android:id="@+id/etTestBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout1"
android:layout_centerHorizontal="true"
android:onClick="test"
android:layout_marginTop="20dp"
android:text="Test" />
<Button
android:id="@+id/etbtnNormal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/etTestBtn"
android:layout_below="@+id/etTestBtn"
android:background="@drawable/button_normal"
android:onClick="normalPressed"
android:text="" />
</RelativeLayout>
IF You Have faced any Problem Comment here I will try to
solution it. Thanks for stay us.
No comments:
Post a Comment