How to create this Setting Layout in android? - java

I want to create a settting UI like this in android:
Questions:
How to create the layout? I believe it's a Vertical LinearLayout containing some of TextView with Divider set, is that right?
How to create sub-textview? (see the image above)
How to create a checkbox which aligned at right? (again, see the image above)
Look at the image above, the "Keypress popup" can be clicked and it will show up a dialog. How to create a clickable TextView? I have tried giving android:onClick on the TextView, but nothing happened when I clicked the TextView.

PreferenceActivity will help you to implement all these very easily. Go through this and this tutorials.
PreferenceFragment should be used post Honeycomb.

Related

How to expand a cardView to show hidden elements in android with a dropping animation?

I am beginner in android animations and therefore, am wondering exactly how can I implement something like expand a cardView to show hidden options or elements.
For example: a post in social networking, we have a cardView holding the post info. it also has likes and comments buttons/options. When user taps on comments button the view should expand a little say certain height and show the comments and shrink back when the same button is tapped again.
I am listing my posts using RecyclerView in a Fragment using a CardView. I am looking for a soft animation along with expanding and shrinking back to original place or size.
Below is a screenshot that might help you understand what exactly I want:
How to do this? Will you please provide me a small snippet of code?
use wrap content as height of cardview and use textview inside it below title, so on click make the textview visible and invisible.
And use android:animateLayoutChanges="true" in parent layout.

How to control the width or the visibility of an activity

I'm using this awesome library Dragger to add drag features to my activity, but is there a way to limit the width of the activity when it shows up or dragged..!? I don't want it to fill the entire screen..! kinda like the drawer navigation menu (see the pic below).
I was thinking of Dialog Activity, but it seems to be concerned with dialogs only and won't allow filling the other 3 sides or I not fully understand it..!
Any help?
Activity is not a view, so it does not have a size. Its' layout views do however.
You can try changing their sizes. Or, as it is an animation lib, you can try modifying existing or adding your own animations where views change sizes when moving. You can modify this param:
<item name="android:windowAnimationStyle">#null</item>
This might help you.

Android Default Button Click effect Is Not Shown

I wanted to implement the android default button click effect on a Relativelayout. (The material design one)
But the problem is that it works on a view like TextView, But it's not working on a RelativeLayout(I want the relativelayout to have the android default button click effect , just like a normal button ).
I have used :
style="?borderlessButtonStyle"
and
style="?buttonStyle"
But none of them seem to work. They both work on a TextView but not on a Relativelayout. Any thoughts ? Any help is greatly appreciated.
Add this to your layout:
android:background="?android:attr/selectableItemBackground"
Have you added a not null OnClickListener to your RelativeLayout?
And make sure that the layout is clickable with (in xml):
android:clickable="true"
or, in code:
relativeLayout.setClickable(true);

Android Button background Image changes back to state in XML

I have a simple soundboard which uses Buttons to represent the sounds. When a sound button is clicked. The background image is changed using the view.
Button butt = (Button)view;
butt.setBackgroundResource(buttons_on[media]);
buttons_on is a int[] representing the drawables of the buttons.
This all works perfect, but I also use a FragmentActivity to create a paged App. The App has 4 different pages which you can swipe through. When I change a button using the above code and swipe two pages to the right and than swipe back. The image of the button has changed back to it's default defined in the page.xml.
How can I prevent this behavior?
change the Buttons to ImageButtons and setting the src?
somehow prevent the page from reloading
Instead of doing that you should look at how to use a StateListDrawable. It will simplify your approach.

Impossible to update the text of a textview in a RelativeLayout

I have a simple screen created in xml, the parent layout is a "relativelayout" and i have a child layout (who is also a "RelativeLayout" containing 3 textview inside).
the only thing I have to do is press a button and change the values ​​of textviews.
to change the text is obviously this:
MyTextView.SetText("Text");
the code runs perfectly, but does not refresh the text of the textviews in the layout.
but when the screen is rotated, the screen refreshes, and the label gets the correct value.
Why does this happen? Why when pressing the button I can not update the text?
I tried using "AsyncTask" and the text is not updated either.
Did something simple can be so problematic. ?
greetings.
Your code
MyTextView.SetText("Text");
Should be executed on UI thread to give effect say suppose if you want it to be updated after button click then this code should be inside your onClickButton listener of your button
Visit This Link for more details

Categories