2014-09-02 3 views
0

위젯의 배경색을 변경하고 싶지만 작동하지 않습니다 (색상 변경되지 않음). 이유를 모르겠습니다. 내 구성 활동에위젯 색상을 변경할 수 없습니다.

나는 색상을 변경할 수있는 버튼이, 예를 들면 :

button_black_bg.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 

       background_color_int = 0x000000; 

       //set color in widget-preview 
       widget_background_preview.setBackgroundColor(background_color_int | (background_opacity_int << 24)); 

      } 
     }); 

두 번째 버튼은 불투명도 변경 : 지난

button_bg_alpha_50.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 

       background_opacity_int = 0x80; 
       widget_background_preview.setBackgroundColor(background_color_int | (background_opacity_int << 24)); 

      } 
     }); 

을의 'accept' 버튼 :

button_accept.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 

        Intent intent = getIntent(); 
        Bundle extras = intent.getExtras(); 

        if (extras != null) { 
         mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, 
           AppWidgetManager.INVALID_APPWIDGET_ID); 
        } 

        remoteViews.setInt(R.id.widget_relative, "setBackgroundColor", background_color_int | (background_opacity_int << 24)); 

       AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getBaseContext()); 
       appWidgetManager.updateAppWidget(mAppWidgetId, remoteViews); 

       Intent resultValue = new Intent(); 
       resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); 

       setResult(RESULT_OK, resultValue); 
       finish(); 

답변

0

위젯은 RemoteView입니다. 위젯의 UI를 업데이트하는 데는 제한된 리소스가 있으므로 직접해서는 안됩니다. 색상

RemoteViews remoteViews = new RemoteViews(context.getPackageName(), 
          R.layout.your_layout); 
remoteViews.setInt(viewId, "setBackgroundColor", Color.BLACK);//this line for changing background colour 

변경 Color.BLACK (AN interger 값) 당신의 선택의 :

당신은 이런 식으로 뭔가를 시도 할 수 있습니다.

관련 문제