【发布时间】:2017-06-19 20:19:35
【问题描述】:
当我向应用程序发送数据时遇到问题,我只接收消息,但我想更改按钮形状等,但它不起作用
package com.pioneer.it.gcmpro;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class PushReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String title="P";
String text="T";
if(intent.getStringExtra("message")!=null)
text=intent.getStringExtra("message");
Intent i=new Intent(context,MainActivity.class);
PendingIntent pi=PendingIntent.getActivity
(context,0,i,PendingIntent.FLAG_UPDATE_CURRENT);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.activity_main,null);
Button b = (Button) v.findViewById(R.id.button);
b.setText("" + text);
Toast.makeText(context, "" + text, Toast.LENGTH_SHORT).show();
}
}
此行仅适用 Toast.makeText(context, "" + text, Toast.LENGTH_SHORT).show();
但这行不起作用 b.setText("" + text);
为什么?
【问题讨论】:
标签: android