android-button

Switch (Button) throws NullPointerException

筅森魡賤 提交于 2019-12-13 05:24:40
问题 I know this question already exists, but I tried serveral solutions and none worked for me. In my case, I need a Switch Button in the ActionBar. I tried to manually add a minSdk Verision I tried to use the id of the item in the defined xml Edit: The exception-point in the code is marked with a comments. It's in the mainactivity. :) Here is some of my code: mainactivity: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout

Android Button layout with big text size

会有一股神秘感。 提交于 2019-12-13 03:58:16
问题 I'm trying to make two identical buttons with the same height, but when the text is too long (the second button) then breaks markup. How can I fix it? xml layout: <?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:layout_height="match_parent"> <LinearLayout android:layout_height="wrap_content" android:layout_width="match_parent"> <Button android:text="test"

how to disable a button when the recyclerview is empty?

拈花ヽ惹草 提交于 2019-12-13 03:06:36
问题 I have a RecyclerView with one text view inside it, and I have one EditText and two buttons ( Add Button & Remove Button ) the RecyclerView takes all the values from the EditText after I press the Add Button , and I delete the last item in the RecyclerView with Remove Button but when the list is empty and I press Remove Button the app crashes. I would like to disable Remove Button when the list is empty. activity_main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=

Adding multiple values to a textView - Android

放肆的年华 提交于 2019-12-13 02:15:08
问题 I'm currently trying to make a basic app that incorporates 4 toggle buttons and a textview. The idea is simple: When a button is pressed, the textview will show which buttons are currently being pressed. This can include multiple buttons (such as if, for example 1, 3, and 4 were pressed). Here's the code I've written for it: TextView buttons; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); buttons =

Animating Drawable change in a Button

删除回忆录丶 提交于 2019-12-13 00:24:41
问题 I have a Button that has a BitmapDrawable and a row of text in it. Not that it matter but my drawable is "above" my text which would correspond to the third button from the top. The drawable is set using: BitmapDrawable top = new BitmapDrawable(mContext.getResources(), Bitmap.createScaledBitmap(buttonContent.content, mContext.IMAGE_WIDTH, mContext.IMAGE_HEIGHT, false)); button.setCompoundDrawablesWithIntrinsicBounds(null, top.getCurrent(), null, null); The image that I set initially changes

button is squeezed when it exceeds layout

耗尽温柔 提交于 2019-12-12 20:47:41
问题 In my code, I create buttons dinamically. When I create multiple buttons is the following problem: How do I get it when it happens the button is put down? My code: private void showGlossary(String ContentTab) { LinearLayout layout; LinearLayout.LayoutParams p; layout = (LinearLayout) findViewById(R.id.GlossaryTab1); p = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.FILL_PARENT ); Glossary = (TextView) findViewById(R.id.glossary); Glossary

Creating multiple buttons programmatically: Android

巧了我就是萌 提交于 2019-12-12 20:04:37
问题 I know that this has been asked several times before but I can't get a solution to mine issue. I am trying to add multiple buttons programmatically. I want the buttons to be aligned horizontally. However, only one button is showing up. What I have tried so far is, private void locationSort() { RelativeLayout townLayout = (RelativeLayout) locationLayout.findViewById(R.id.town_sort); for (int i = 0; i <= 3; i++) { LayoutInflater inflater = getLayoutInflater(); Button btnTag = (Button) inflater

How to set a gradient background to a Material Button?

帅比萌擦擦* 提交于 2019-12-12 14:32:21
问题 I'm currently using this code but the background is not changing.It is still showing accent-color as background. <com.google.android.material.button.MaterialButton android:id="@+id/materialButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello" app:cornerRadius="32dp" android:background="@drawable/gradiant_blue"/> gradiant_blue.xml <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:angle=

change statelistdrawable text color android button

为君一笑 提交于 2019-12-12 12:27:36
问题 I'm developing android application I have a different background drawable and text color for each status of the button (pressed , normal) I have created statelistdrawable object to be able to add the background drawable , but my problem now is how to set the text color can any one help please ? 回答1: Button is a TextView and you can call button.setTextColor(someColorStateList) on a TextView. Here is how to do it programmatically: ColorStateList colorStateList = new ColorStateList( new int[][]{

Make button invisible for 5 seconds

不想你离开。 提交于 2019-12-12 07:05:34
问题 Goal: When you start the app, The Button should be visible after 5 seconds. In order words, Start the app -> Hide a button -> Wait 5 seconds -> Display the button Problem: The code doesn't work and what part am I missing? Info: *Im new in android, This what i try public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Button button2 = (Button) findViewById(R.id.btn_test); button2.setVisibility