Android widget: How to change the text of a button

前端 未结 7 1557
野性不改
野性不改 2020-12-13 06:31

How can I change the text of an Android button widget within code and not the XML file?

7条回答
  •  暖寄归人
    2020-12-13 06:50

    I was able to change the button's text like this:

    import android.widget.RemoteViews;
    
    //grab the layout, then set the text of the Button called R.id.Counter:
    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.my_layout);
    remoteViews.setTextViewText(R.id.Counter, "Set button text here");
    

提交回复
热议问题