android-ui

EditText's cursor position

孤人 提交于 2019-12-01 03:30:13
Assuming, that a user has written some text into an EditText and thereafter touched somewhere else on the screen, which caused the cursor position to change: How can one determine the new cursor position? The simple version: myEditText.getSelectionStart(); If you want to react on an event you may try myEditText.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { // view is myEditText here } }); event allows to distinguish between presses and releases. EditText also has a setOnClickListener() that might be worth to look at. EDIT: I

Is it possible to launch a DialogFragment from a Preference in a PreferenceActivity?

家住魔仙堡 提交于 2019-12-01 03:24:12
I am converting my app to use the v4 compatibility package and fragments. I have done well so far, but I need to launch a DialogFragment from a preference click in a PreferenceActivity . Since there isn't a PreferenceFragment in the compatibility library, I'm stuck with using PreferenceActivity . Is it possible to get a reference to the fragment manager and call the DialogFragment or do I just have to continue using the old dialog if I need a dialog from a preference? Not without jumping through hoops. You could make a very simple activity with the sole purpose of launching the DialogFragment.

Android translucent background with shadow

北城余情 提交于 2019-12-01 01:32:36
I'm trying to create a background drawable resource in XML that is translucent, but with a solid shadow. This is what I have so far: <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle" > <padding android:top="-2dp" android:left="-2dp" android:right="2dp" android:bottom="2dp" /> <gradient android:startColor="@android:color/transparent" android:centerColor="#33333333" android:endColor="#aa666666" android:angle="90"/> </shape> </item> <!-- Background --> <item> <shape> <solid android:color="

ShapeDrawable as progressDrawable for RatingBar in Android?

时光怂恿深爱的人放手 提交于 2019-12-01 00:05:34
It seems I cannot set ShapeDrawable as progressDrawable for Ratingbar. I tried the following but failed: <RatingBar android:id="@+id/ratingbar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:numStars="5" android:stepSize="1.0" android:rating="3.0" style="@style/myRatingBar" /> myRatingbar style: <style name="myRatingBar" parent="@android:style/Widget.RatingBar"> <item name="android:progressDrawable">@drawable/ratingbar_full</item> <item name="android:indeterminateDrawable">@drawable/ratingbar_full</item> <item name=

Android: Make multiline edittext scrollable, disable in vertical scroll view

为君一笑 提交于 2019-11-30 23:14:39
I am developing an application in which i am struct at a point. As according to my application requirement i created horizontal scrollview in xml and then vertical scrollview in .java as : // Vertical Scroll view in Linear layout ScrollView scrollView = new ScrollView(this); scrollView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); Then i created a table view programatically and added it in scrollview. I created multiline edit text and disable it because i want to set text in it run time and added this in table view as a row.. EditText editText = new

EditText's cursor position

我只是一个虾纸丫 提交于 2019-11-30 23:09:16
问题 Assuming, that a user has written some text into an EditText and thereafter touched somewhere else on the screen, which caused the cursor position to change: How can one determine the new cursor position? 回答1: The simple version: myEditText.getSelectionStart(); If you want to react on an event you may try myEditText.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { // view is myEditText here } }); event allows to distinguish

When are child views added to Layout/ViewGroup from XML

泪湿孤枕 提交于 2019-11-30 22:58:35
问题 My question is : I want to know when does a xLayout (or ViewGroup in general) add a child view from XML ? And by "when" I mean at what point of code, in what "pass" of the "traversal" of the UI toolkit ? Which method of xLayout or ViewGroup should I override ? I have done my homework : I have watched the "Writing Custom Views For Android" presented (by Adam Powell and Romain Guy) in the last Google I/O and I have read Adam Powell comments on this Google+ post. 回答1: Looking for the exact point

setMinDate(…) for DatePicker doesn't work when invoked a second time

丶灬走出姿态 提交于 2019-11-30 22:07:06
问题 I'm in a particular situation in which I have to alter the min and max date of DatePicker according to the selected element of a Spinner . Here's the chunk of code I'm using to switch min and max date. private void switchCalculationMethod(int method) { calculationMethod = method; switch (method) { case METHOD_1: datePicker.setMinDate(new LocalDate().minusWeeks(42).getMillis()); datePicker.setMaxDate(new LocalDate().plusDays(1).getMillis() - 1); break; case METHOD_2: datePicker.setMinDate(new

Disabling the send button when the EditText is empty when using imeOption= actionSend

前提是你 提交于 2019-11-30 22:05:34
When the text is empty, we want to disable the button (which is how it's set on portrait mode) Any ideas? Edit: I don't think it's clear but I can enable/disable my own button.. But when using the landscape mode, when the keyboard pops up, the screen is covered by an android specific text area with it's own button (hence the imeOption) So I don't have a problem enabling/disabling the button I have.. It's this Android button that I want to disable when the text area is empty.. FunkTheMonk Add a TextChangedListener which will get called whenever the text inside the EditText gets changed. message

How do I create an Android material design UI widget?

给你一囗甜甜゛ 提交于 2019-11-30 21:02:35
I did read new android material design guide but i am not able to find anything about how to create this UI widget(element). Apps like Gmail, S converter etc has updated their apps to support new material design. I have added screenshot of it. Here is the link to it. because of low points i can't put the picture. sorry about it Any suggestions on how shall i make it?? You are talking about the Floating Action Button. Bottom line is: there is no native "FAB" widget (at least for now), it is a custom layout that must be implemented. If you really want to fully implement a Material Design app, I