<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="\u00A9 Android Elements 2011" />![]() |
| Displaying the copyright notice in an app |
Android basics, tutorials, app reviews, news and more
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="\u00A9 Android Elements 2011" />![]() |
| Displaying the copyright notice in an app |
final String phoneNumber = "01234 123456";
startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phoneNumber)));
![]() |
| Android dialler intent |
InputMethodManager inputMgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
EditText editText = (EditText)findViewById(R.id.editText);
inputMgr.hideSoftInputFromWindow(editText.getWindowToken(), 0);![]() |
| Cannot complete the install because of a conflicing dependency |
Drawable d = getResources().getDrawable(R.drawable.icon);
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.androidelements.myProject" android:versionCode="1" android:versionName="1.0.0">
import android.content.pm.PackageInfo; import android.content.pm.PackageManager.NameNotFoundException;
String versionName = "";
try {
final PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
versionName = packageInfo.versionName;
} catch (NameNotFoundException e) {
e.printStackTrace();
}
TextView tv = (TextView) findViewById(R.id.tvVersion);
tv.setText(versionName);
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="This is a template" style="@style/my_style" />
TextView myText = (TextView)getLayoutInflater().inflate(R.layout.tvtemplate, null);
import android.widget.Button;
Button myButton = new Button(this);
myButton.setText("Tap Me");
LinearLayout layout = (LinearLayout) findViewById(R.id.layout1); layout.addView(myButton);
project/assets/fonts/myfont.ttf
TextView tv = (TextView)findViewById(R.id.TextView1); Typeface face = Typeface.createFromAsset(getAssets(), "fonts/myfont.ttf"); tv.setTypeface(face);
<activity
android:name=".myActivity"
android:screenOrientation="portrait">
myActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
res/menu/example.xml
<?xml version="1.0" encoding="utf-8"?><menu xmlns:android="http://schemas.android.com/apk/res/android"><item android:id="@+id/menu_refresh"android:icon="@drawable/ic_menu_refresh"android:title="Refresh" /></menu>
import android.view.Menu; import android.view.MenuInflater; import android.view MenuItem;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.example, menu);
return true;
}
The second method handles the menu item selection. Here I use a case statement to react in response to the ID of the tapped menu item: @Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_refresh:
// Refresh something
return true;
default:
return super.onOptionsItemSelected(item);
}
}
![]() |
| Android app with menu |
String webPageUri = "http://android-elements.blogspot.com/"; Uri uri = Uri.parse(webPageUri); if (uri != null) { Intent myIntent = new Intent(Intent.ACTION_VIEW, uri); startActivity(myIntent); }
<uses-permission android:name="android.permission.INTERNET" />