简体   繁体   中英

how can I edit the text on a button?

If you are reading this, I want to ask you a question (obviously). So uhh, I kinda have this problem on my emulator in android studio where the text on the button is not edited. How do I solve this? the original thing (left) what it shows on the emulator (right)

Usually you do this from the XML code

<Button
        android:id="@+id/btn_addCamera"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Click Me!"/>

Or you can do this programmatically

Button button = findViewById(R.id.button);
button.setText("Click Me!");

To set Button text, you can assign android:text XML attribute for Button in layout file with the required value.

To programmatically set or change Android Button text, then pass the specified string to the method Button. setText(new_string_value)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM