<TextView
android:textAllCaps="true"
/>
android:textAllCaps="true"
/>
<EditText
android:inputType="textCapWords"
/>
<EditText
android:inputType="textCapWords"
/>
activity.getSupportFragmentManager().beginTransaction()
.replace(R.id.main_activity_content, userProfileFragment)
.addToBackStack(UserProfileFragment.BACK_STACK_NAME)
.commit();
Remove from back stack
getMainActivity().getSupportFragmentManager()
.popBackStackImmediate(UserProfileFragment.BACK_STACK_NAME,FragmentManager.POP_BACK_STACK_INCLUSIVE);
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE))
.getDefaultDisplay();
int orientation = display.getRotation();
Usage
if (orientation == Surface.ROTATION_90 || orientation == Surface.ROTATION_270) {
// ...
}
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
public class OnSwipeTouchListener implements OnTouchListener {
private final GestureDetector gestureDetector =
new GestureDetector(new GestureListener());
public boolean onTouch(final View view, final MotionEvent motionEvent) {
return gestureDetector.onTouchEvent(motionEvent);
}
private final class GestureListener extends SimpleOnGestureListener {
private static final int SWIPE_THRESHOLD = 100;
private static final int SWIPE_VELOCITY_THRESHOLD = 100;
@Override
public boolean onDown(MotionEvent e) {
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2,
float velocityX, float velocityY) {
boolean result = false;
try {
float diffY = e2.getY() - e1.getY();
float diffX = e2.getX() - e1.getX();
if (Math.abs(diffX) > Math.abs(diffY)) {
if (Math.abs(diffX) > SWIPE_THRESHOLD &&
Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
if (diffX > 0) {
onSwipeRight();
} else {
onSwipeLeft();
}
}
} else {
if (Math.abs(diffY) > SWIPE_THRESHOLD &&
Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
if (diffY > 0) {
onSwipeBottom();
} else {
onSwipeTop();
}
}
}
} catch (Exception exception) {
exception.printStackTrace();
}
return result;
}
}
public void onSwipeRight() {
}
public void onSwipeLeft() {
}
public void onSwipeTop() {
}
public void onSwipeBottom() {
}
}
view.setOnTouchListener(new OnSwipeTouchListener() {
public void onSwipeTop() {
Toast.makeText(MyActivity.this, "top", Toast.LENGTH_SHORT).show();
}
public void onSwipeRight() {
Toast.makeText(MyActivity.this, "right", Toast.LENGTH_SHORT).show();
}
public void onSwipeLeft() {
Toast.makeText(MyActivity.this, "left", Toast.LENGTH_SHORT).show();
}
public void onSwipeBottom() {
Toast.makeText(MyActivity.this, "bottom", Toast.LENGTH_SHORT).show();
}
});
<EditText
...
android:background="@drawable/rounded_edit_text"
... />
res/drawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners
android:bottomLeftRadius="3dp"
android:bottomRightRadius="3dp"
android:radius="5dp"
android:topLeftRadius="3dp"
android:topRightRadius="3dp" />
<solid
android:color="@android:color/white"/>
</shape>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/gridview_no_results"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:src="@drawable/background_no_results" />
<GridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
... />
</RelativeLayout>
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
gridables = new ArrayList<CalendaredProgram>();
gridView = (GridView) view.findViewById(R.id.gridview);
ImageView noResultsView = (ImageView) view.findViewById(R.id.gridview_no_results);
gridView.setEmptyView(noResultsView);
this.setSearchButtonOnClickHandler();
}
private class SearchTask extends AsyncTask{ ... @Override protected void onPostExecute(Response response) { // Assign empty list if there are no results } @Override protected TaskResult doInBackground(Params... params) { // Do request } }
public class SingletonClass {
private static class Holder {
static final SingletonClass INSTANCE = new SingletonClass();
}
public static SingletonClass getInstance() {
return Holder.INSTANCE;
}
// ...
}
public int getStatusBarHeight(Activity activity) {
Rect rectgle = new Rect();
Window window = activity.getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
return rectgle.top;
}
// Screen size, it includes the action bar in its calculation
//
private static DisplayMetrics getScreenMetricsIncludingActionBar() {
return Resources.getSystem().getDisplayMetrics();
}
// Screen size removing the action bar
//
private static DisplayMetrics getScreenMetricsRemovingActionBar(
Activity activity) {
DisplayMetrics metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
return metrics;
}
public static int getStatusBarHeight(Activity activity) {
Rect rectgle = new Rect();
Window window = activity.getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
return rectgle.top;
}
final TypedArray styledAttributes = getContext().getTheme().obtainStyledAttributes(
new int[] { android.R.attr.actionBarSize });
mActionBarSize = (int) styledAttributes.getDimension(0, 0);
styledAttributes.recycle();
<ImageView
android:id="@+id/gallery_button"
style="@style/ProgramDetailMenuItem"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true"
android:src="@drawable/galery_button_selector" />
res/drawable/galery_button_selector
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@drawable/btn_galery_pressed"
android:state_pressed="true"/>
<item
android:drawable="@drawable/btn_galery"
android:state_enabled="true"/>
</selector>
Now we do the background color change.
<resources xmlns:android="http://schemas.android.com/apk/res/android">
...
<style name="ProgramDetailMenuItem">
<item name="android:background">@drawable/program_detail_button_background</item>
</style>
</resources>
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@color/program_detail_button_pressed" android:state_pressed="true"/> <item android:drawable="@color/program_detail_button_not_pressed" android:state_enabled="true"/>
</selector>
<?xml version="1.0" encoding="utf-8"?><resources> ... <color name="program_detail_button_pressed">#717171</color> <color name="program_detail_button_not_pressed">#00FFFFFF</color> </resources>
The reason behind #00FFFFFF is that 00 is the alpha, and this value will set the alpha to 0 regardless of the following 6 hexa digits.
<ImageView
... android:clickable="true"
android:src="@drawable/favorite_button_selector"
android:onClick="favoriteClicked" />
res/drawable
TextView title = (TextView) convertView.findViewById(R.id.highlight_title);
title.setTypeface(null, Typeface.BOLD);
title.setText(calendaredProgram.getProgram().getTitle());
you can also do the following
Spanned fromHtml = Html.fromHtml("<b>Text</b>");
String text = fromHtml.toString();
In the view layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
...
<TextView
android:id="@+id/highlight_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
...
android:text="@string/highlight_title"
... />
...
</RelativeLayout>
values/strings
<resources>
...
<string name="highlight_title"><b>Some text</b></string>
</resources>
In the layout
<TextView xmlns:android="http://schemas.android.com/apk/res/android"