android-button

Common class for click listener

烈酒焚心 提交于 2019-12-06 23:07:12
问题 I have 7 buttons in all my 6 activities. All 6 buttons have the same functionality in all activities. How can I perform a common click event lisnter for these 6 buttons. 回答1: You can create a new class that implements View.OnClickListener like this: public class MyClickListener implements View.OnClickListener { @Override public void onClick(View view) { // TODO handle the click } } In all your activities you can then set the click listener like this: button.setOnClickListener(new

How to set Floating Action Button image to fill the button?

孤街浪徒 提交于 2019-12-06 21:59:38
问题 Usually icons are set for floating action buttons, but I need to set an image, so I can make a circular image. I added it to the project (using Android Studio-> New -> Image Asset), but the image didn't fill the entire button: My xml: <com.github.clans.fab.FloatingActionMenu android:id="@+id/run_menu" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:paddingBottom="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin"

Android - ListView onClick() open a website

戏子无情 提交于 2019-12-06 16:13:39
问题 I am trying to open a website when I clicked a item from the list.For example when click item 'A' open www.google.com click 'b' open another website. How to do that? thanks. public class MainActivity extends Activity { private ListView lv; /////////// /////////////////////// // Listview Adapter ArrayAdapter<String> adapter; // Search EditText EditText inputSearch; // ArrayList for Listview ArrayList<HashMap<String, String>> productList; @Override public void onCreate(Bundle savedInstanceState

how could find out the end of text position in textview?

為{幸葍}努か 提交于 2019-12-06 13:16:21
after asking a question about Place Button just after end of TextView in multilline TextView I give no answer but I think if find the position of end character of final line of textview , then my problem is solved . so how could find out the end of text position in last line of textview? tank's for your help and your attention. CharSequence cs = textView.getText(); int position = cs.charAt(cs.length()-1); 来源: https://stackoverflow.com/questions/17306961/how-could-find-out-the-end-of-text-position-in-textview

Is there a way to create a triangular button on Android?

南笙酒味 提交于 2019-12-06 11:40:22
Is there a way I can create a button which is shaped as a triangle? I know I can put a triangle image as background, but this will make the area outside the triangle clickable. Is there a way to sey the button corners X and Y so I could make it triangular? You can override the OnTouch Event method in a CustomView / CustomButton Inside you have the MotionEvent were you can check if the Touch was inside your Triangle (with the help of some mathematics :P) If you want to get exotic with non-rectangular views, then you will want to create a custom View. There is lots of information available on

Overriding lock/power button in android devices

烈酒焚心 提交于 2019-12-06 11:34:59
I would like to know if its possible to override power button in android? I read a lot of posts in Stack Overflow, some saying it's possible and some saying it's not ( example ). What I am trying to achieve is that - when user is using my app he needs to press the lock/power button 5 times to lock the screen. I dont want to override the swtich off functionality only the lock one. Is there anyway to fetch power button callback? I tried WakeLock and disabled the keyguard but it does'nt serve my pupose. I tried out below code from Shink link posted in comments section below: @Override public

Change textView while moving finger across buttons

时光毁灭记忆、已成空白 提交于 2019-12-06 11:13:00
In my app, I have an activity in which there are 9 buttons and 1 textView . I am making use of OnTouchListener to change the text in the textView as I move my finger accross the buttons. This is what my activity looks like: Here is my java code: button1.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { textView.setText("Button 1"); return false; } }); button2.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { textView.setText("Button 2"); return false; } }); button3

How to properly style material buttons in android

笑着哭i 提交于 2019-12-06 11:00:56
问题 I am going after flat buttons for my example, but the question really applies to all buttons. Why does it seem so hard to find documentation on the proper way to style material buttons in android. I have the following which I messed around with until I could get it to work. Felt like a hack so I am not sure if this is really the right way to do it. <Button android:id="@+id/apply" style="?android:attr/borderlessButtonStyle" android:layout_width="wrap_content" android:layout_height="wrap

How can I make an animated/constant glowing effect around button in android?

安稳与你 提交于 2019-12-06 08:10:25
问题 I am seeking to make two buttons have a thin glow around them, kinda pulsating-fading effect The buttons have a background drawable image, and i just wanna have a glowing effect around it to make it kinda resonate with the music playing I have already searched around multiple threads, and they were either just about an imageView, or upon pressed, or a Bitmap, so not necessarily what I am seeking Here is my Button XML: <Button android:id="@+id/playEasyMode_Button" android:layout_width="145dp"

How to apply an style to all ImageButtons in Android?

给你一囗甜甜゛ 提交于 2019-12-06 08:06:45
问题 I have the following style in my application. <style name="BtnPressed"> <item name="android:background">@drawable/btn_default</item> </style> Now I want to apply that to all the ImageButtons in my application. I tried to use the solution mentioned in this question but it did not work. I'm using API-7. 回答1: Change your BtnPressed style to this: <style name="BtnPressedStyle" parent="Widget.ImageButton"> <item name="android:background">@drawable/btn_default</item> </style> Define an application