android-button

Android - 9patch padding on a Button

坚强是说给别人听的谎言 提交于 2019-12-24 16:25:45
问题 I created a button with a 9patch image as a background. In the 9patch image I used the bottom and right lines to specify the content area/padding, to position the text on the button. This works well on a TextView, but on a Button the content lines seem to have no effect on the text position. Setting "paddingTop"/"paddingBottom" also seem to have no effect - only "padding" has any effect. This is my layout XML: <Button android:layout_width="450dp" android:layout_height="198dp" android:text=

Saving State for EditText and Button Clicks

喜夏-厌秋 提交于 2019-12-24 11:33:57
问题 I have 2 Activities. First Activity has EditText and Next Button . Second Activity has one Back Button . In First Activity I entered some texts in EditText and I hit Next Button . Now I'm in SecondActivity , If I press Back Button it will return to First Activity clearing the EditText fields. I want that EditText field to remain same. How to achieve these steps? FirstActivity: public class HomeActivity extends Activity { EditText text; Button button; @Override protected void onCreate(Bundle

Make multiple clickacble areas in an image

回眸只為那壹抹淺笑 提交于 2019-12-24 05:08:07
问题 I have an image, and I want to preform a different action if the user clicked on different parts of the image. I am kinda of new hobbyist, so I don't understand everything I find on my research. I have found a couple of solutions, but I don't quite understand how to implement any Mask the image and get the pixel color of that underneath image to know which area has been clicked ImageMap PS: The image is in a gird like a table (if it will help)(drawing the table is NOT an option) I have seen a

Android Buttons not scaling

*爱你&永不变心* 提交于 2019-12-24 00:57:21
问题 This seems like a very basic question but I can't seem to figure it out. I have done quite a bit of reading on how to make android scalable to big and small screens. I have an app that is designed for a tablet and works great on there. However, while I am working on the mobile(phone) version I want to ensure it will at least look "ok" if someone opens it on a phone. Everyone scales great besides the buttons.... I just can't seem to get the buttons to scale. They look great on the Tab...but on

Odd behavior of button in linear layout that has one line of text instead of two

蹲街弑〆低调 提交于 2019-12-24 00:02:50
问题 I have a linear layout wrapped in a HorizontalScrollView . Everything seems to be working fine except that one of the buttons in the layout is higher then the rest. The reason this button seems to be higher then the rest of the buttons is because it only has one line of text instead of two. Here is a screenshot of the problem: While the layout is being used for a keyboard service, I do not think that is the problem because in the design tab of the XML layout file this problem still occurs.

extending android button by using onDraw

孤者浪人 提交于 2019-12-23 13:19:59
问题 I want to change my button shape BUT I WANT TO USE onDaw method and EXTENDING button class. So what I've just done for the beginning is : <view class = "com.example.button.MainActivity$MyButton" android:layout_width="wrap_content" android:layout_height="wrap_content" /> and public static class MyButton extends Button { public MyButton(Context context) { super(context); } public MyButton(Context context, AttributeSet attrs) { super(context, attrs); } public MyButton(Context context,

How to display dynamic text on a button and auto adjust their size in Android?

此生再无相见时 提交于 2019-12-23 09:00:02
问题 I'm working on a project which needs me to display some dynamic texts based on users' selection on a button. I know how to do the text display part, but I was stuck on how I can display different text properly on a fixed size button. For example: "Apple" and "I have an Apple". How can I achieve the result that when displaying "Apple", the text size will be bigger and fit the button, and when "I have an Apple" the text will be smaller and may become three lines? Thank you! 回答1: Take a look at

How to check if a user has already clicked a Button?

删除回忆录丶 提交于 2019-12-23 06:14:15
问题 I have a button in my menu with a “promo code” inside. I need to check if a user already clicked it so I can tell him (the next time he clicks it) “You already redeemed this promo code!” How do I do that? I need only the piece of code where I can check for button clicked. @Override public boolean onOptionsItemSelected(MenuItem item) { boolean clicked = false; switch (item.getItemId()) { case R.id.getcode: SharedPreferences pref = getSharedPreferences("promo", MODE_PRIVATE); boolean activated

How to set the state_pressed of a button

梦想的初衷 提交于 2019-12-23 03:59:06
问题 I use a xml file to color my button. In the xml a have this code to define the color of my button when it's clicked. <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" > <shape> <gradient android:startColor="@color/mainRaddoppiaButtonBackgroundEnd" android:endColor="@color/mainRaddoppiaButtonBackgroundStart" android:angle="270" /> <stroke android:width="0dp" android:color="@color

How to place transparent buttons over an image relatively?

痴心易碎 提交于 2019-12-23 02:54:24
问题 I am looking for a way in Android how to place some transparent buttons over a (background) image so I have good control to position the buttons and they stay were they meant to be also if the screen is much larger. As you can imagine the image contains also the button art... The best thing would be if I could position the buttons by using percentage, but sadly this is not possible in Android. This is my current base of the code: <RelativeLayout xmlns:android="http://schemas.android.com/apk