我已经在一个小部件中成功实现了一个 EditText。通过使用以下代码。
<TextView
android:id="@+id/edit_widget"
style="@android:style/Widget.EditText"
android:layout_width="150dp"
android:layout_height="29dp"
android:layout_margin="5dp"
android:hint="Enter Name"
android:inputType="number"
android:nextFocusDown="@+id/btnSave"
android:paddingLeft="5dp"
android:textSize="15sp" >
</TextView>
<Button
android:id="@+id/widget_button"
style="@style/normal_button_gray"
android:layout_width="74dp"
android:layout_height="29dp"
android:layout_margin="4dp"
android:gravity="center"
android:minHeight="0dp"
android:minWidth="0dp"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:text="@string/label_Add"
android:textColorHint="@color/dark_gray"
android:textSize="14sp" />
以下代码使用 A 类和扩展 BroadcastReceiver
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_demo);
remoteViews.setTextViewText(R.id.ed_expersivecost, "");
remoteViews.setTextViewText(R.id.txt_appname,context.getString(R.string.app_name));
remoteViews.setOnClickPendingIntent(R.id.widget_button, MyWidgetProvider.buildButtonPendingIntent(context));
以下代码使用 B 类扩展 AppWidgetProvider
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_demo);
remoteViews.setOnClickPendingIntent(R.id.widget_button, buildButtonPendingIntent(context));
//how to get edittext value in here
}
public static PendingIntent buildButtonPendingIntent(Context context) {
Intent intent = new Intent();
intent.setAction("com.connectingpixles.intent.action.Addamount");
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
但不知道如何从 EditBox Widget 获取文本。任何人都可以帮助我吗?