How to use Android Widgets in Android Studio – Mobile App Development, Android App Development, iphone App Development class="post-template-default single single-post postid-4160 single-format-standard wp-custom-logo"

How to use Android Widgets in Android Studio

Create a new project in Android Studio

File – New Android Project.
How to use Android Widgets in Android Studio
How to use Android Widgets in Android Studio

What a is Widget

A widget is a small gadget or control of your android appliaction palced on the home screen. Widget can be veru handy as the allow to put your favourite application on the screen in order to quickly access them.

Create a Android Widgets

Right click on src/ package-New-Widget-app widget

Creating AppWidgetProvider in XML

This is used to describe the metadata for an app Widget, such as the app Widget’s layout, update frequency, and the AppWidget provider class. This is always defined as XML file.

[code lang=”js”]
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:initialKeyguardLayout="@layout/new_app_widget"
android:initialLayout="@layout/new_app_widget"
android:minHeight="40dp"
android:minWidth="40dp"
android:previewImage="@drawable/example_appwidget_preview"
android:resizeMode="horizontal|vertical"
android:updatePeriodMillis="86400000"
android:widgetCategory="home_screen">
</appwidget-provider>
[/code]

Create the App widget Layout

[code lang=”js”]
<TextView
android:id="@+id/appwidget_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="8dp"
android:background="#09C"
android:contentDescription="@string/appwidget_text"
android:text="@string/appwidget_text"
android:textColor="#ffffff"
android:textSize="24sp"
android:textStyle="bold|italic" />
[/code]

Use AppWidget Provider class

[code lang=”js”]
public class NewAppWidget extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// There may be multiple widgets active, so update all of them
final int N = appWidgetIds.length;
for (int i = 0; i < N; i++) {
updateAppWidget(context, appWidgetManager, appWidgetIds[i]);
}
}

@Override
public void onEnabled(Context context) {
// Enter relevant functionality for when the first widget is created
}

@Override
public void onDisabled(Context context) {
// Enter relevant functionality for when the last widget is disabled
}

static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId) {

CharSequence widgetText = context.getString(R.string.appwidget_text);
// Construct the RemoteViews object
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.new_app_widget);
views.setTextViewText(R.id.appwidget_text, widgetText);
// Create an Intent to launch MainActivity
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.appwidget_text,pendingIntent);

// Instruct the widget manager to update the widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
[/code]

AndroidManifest.xml

We need to register the app widget in your application manifest file. To do this, you will use the tag. This block of XML should be placed inside the application tag in application manifest.
The receiver name is the name of your app widget provider class implementation.

[code lang=”js”]
<receiver android:name=".NewAppWidget" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/new_app_widget_info" />
</receiver>
[/code]


Warning: _() expects exactly 1 parameter, 2 given in /home2/mobilemeri7/public_html/wp-content/themes/mobilemerit/comments.php on line 28

Write a Reply or Comment

Your email address will not be published.


This site uses Akismet to reduce spam. Learn how your comment data is processed.

https://www.ankihlasnakliyat.com/jigolo siteleri arkadaş bulankara nakliyatankara nakliyatistanbul nakliyatankara nakliyathovarda betantalya çittrbetJigolodiyarijigolo sitesijigolo kayitciporndox.com18avx.comtotoleak.comizmir escort bayanalsancak escortbuca escorttercümanlık bürosuistanbul hair transplant pricejigolo sitelerimjigolo şirketlericast ajans yeni yüzlerjigolo sitelerijigolo başvuruxnxxxvideos62.com
#yaslikurt#>
ümraniye escort ataşehir escort escort bayan
Hack haber Hacklink Hack forum Hd film izle php Shell indir Hack haber