Wednesday, June 11, 2014
Create custom dialog :
code:
final Dialog d = new Dialog(myActivity.this);
d.setContentView(R.layout.mylayout);
d.setTitle("my title");
final EditText edit = (EditText)d.findViewById(R.id.txtedit);
Button btn = (Button)d.findViewById(R.id.txtbtn);
d.show();
layout:
<Button
android:id="@+id/btnAdd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<EditText
android:id="@+id/txtItem2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="text" />
How to create a splash screen
public class SplashActivity extends Activity {
private static String TAG = SplashActivity.class.getName();
private static long SLEEP_TIME = 5; // Sleep for some time
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
// Start timer and launch main activity
IntentLauncher launcher = new IntentLauncher();
launcher.start();
}
private class IntentLauncher extends Thread {
@Override
/**
* Sleep for some time and than start new activity.
*/
public void run() {
try {
// Sleeping
Thread.sleep(SLEEP_TIME*1000);
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
// Start main activity
Intent intent = new Intent(SplashActivity.this,mainactivity.class);
SplashActivity.this.startActivity(intent);
SplashActivity.this.finish();
}
}
}
Subscribe to:
Posts (Atom)