widget

阅读更多

1:在清单注册:    

          android:name="com.youku.widget2.LenovoLeosWidgetDemoWidgetProvider"
   android:label="@string/app_name"
   >
           
               
           

           
     
 

 

2:xml 文件夹下demo_info.xml


 xmlns:android="http://schemas.android.com/apk/res/android"
 android:updatePeriodMillis="1800000"
 android:initialLayout="@layout/widget"
 android:minHeight="288px"
 android:minWidth="512px"
 >

 

3.layout文件夹下widget.xml

 


 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="512px"
 android:layout_height="294px"
 android:orientation="vertical"
    >

            android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

                    android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="电视剧" />

                    android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="电视台" />

                    android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="电影" />

   

 

4 在src 下:

 

 

public class LenovoLeosWidgetDemoWidgetProvider extends AppWidgetProvider {
   
    private static final String TAG = "LenovoLeosWidgetDemoWidgetProvider";
   
    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
       
        Log.e(TAG, "----onUpdate-----");
//        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
//        Intent intent = new Intent(context, TargetActivity.class);
//        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

        for (int appWidgetId : appWidgetIds) {
//          views.setOnClickPendingIntent(R.id.button, pendingIntent);
//            appWidgetManager.updateAppWidget(appWidgetId, views);
        }
       
        super.onUpdate(context, appWidgetManager, appWidgetIds);
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        Log.e(TAG, "action ================================== " + action);
        super.onReceive(context, intent);
    }
}

 

5:横竖屏监听 :

在application:

 

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        // TODO Auto-generated method stub
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            Log.e("yy", "当前屏幕为横屏");
        } else {
            Log.e("yy", "当前屏幕为竖屏");
        }
        super.onConfigurationChanged(newConfig);
    }

清单中:

application加上这条语句

android:configChanges="orientation|keyboardHidden"

 

你可能感兴趣的:(widget)