Assign width to half available screen width declaratively

If your widget is a Button: <LinearLayout android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:weightSum=”2″ android:orientation=”horizontal”> <Button android:layout_width=”0dp” android:layout_height=”wrap_content” android:layout_weight=”1″ android:text=”somebutton”/> <TextView android:layout_width=”0dp” android:layout_height=”wrap_content” android:layout_weight=”1″/> </LinearLayout> I’m assuming you want your widget to take up one half, and another widget to take up the other half. The trick is using a LinearLayout, setting layout_width=”fill_parent” on both widgets, and setting layout_weight … Read more

Changing position of the Dialog on screen android

I used this code to show the dialog at the bottom of the screen: Dialog dlg = <code to create custom dialog>; Window window = dlg.getWindow(); WindowManager.LayoutParams wlp = window.getAttributes(); wlp.gravity = Gravity.BOTTOM; wlp.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND; window.setAttributes(wlp); This code also prevents android from dimming the background of the dialog, if you need it. You should … Read more

how to get html content from a webview?

Actually this question has many answers. Here are 2 of them : This first is almost the same as yours, I guess we got it from the same tutorial. public class TestActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.webview); final WebView webview = (WebView) findViewById(R.id.browser); webview.getSettings().setJavaScriptEnabled(true); webview.addJavascriptInterface(new MyJavaScriptInterface(this), “HtmlViewer”); webview.setWebViewClient(new WebViewClient() … Read more

How to make a smaller RatingBar?

How to glue the code given here … Step-1. You need your own rating stars in res/drawable … Step-2 In res/drawable you need ratingstars.xml as follow … <?xml version=”1.0″ encoding=”utf-8″?> <layer-list xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:id=”@android:id/background” android:drawable=”@drawable/star_empty” /> <item android:id=”@android:id/secondaryProgress” android:drawable=”@drawable/star_empty” /> <item android:id=”@android:id/progress” android:drawable=”@drawable/star” /> </layer-list> Step-3 In res/values you need styles.xml as follow … <?xml … Read more

How to create a date and time picker in Android? [closed]

Put both DatePicker and TimePicker in a layout XML. date_time_picker.xml: <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:orientation=”vertical” android:layout_width=”match_parent” android:padding=”8dp” android:layout_height=”match_parent”> <DatePicker android:id=”@+id/date_picker” android:layout_width=”match_parent” android:calendarViewShown=”true” android:spinnersShown=”false” android:layout_weight=”4″ android:layout_height=”0dp” /> <TimePicker android:id=”@+id/time_picker” android:layout_weight=”4″ android:layout_width=”match_parent” android:layout_height=”0dp” /> <Button android:id=”@+id/date_time_set” android:layout_weight=”1″ android:layout_width=”match_parent” android:text=”Set” android:layout_height=”0dp” /> </LinearLayout> The code: final View dialogView = View.inflate(activity, R.layout.date_time_picker, null); final AlertDialog alertDialog = new … Read more

How to dynamically update a ListView on Android [closed]

First, you need to create an XML layout that has both an EditText, and a ListView. <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”fill_parent” android:layout_height=”fill_parent” android:orientation=”vertical” > <!– Pretty hint text, and maxLines –> <EditText android:id=”@+building_list/search_box” android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:hint=”type to filter” android:inputType=”text” android:maxLines=”1″/> <!– Set height to 0, and let the weight param expand it –> <!– Note the use … Read more