据我所知,在互联网和官方文档中,无法制作可滚动的应用程序小部件.我的所有尝试都失败了.我甚至尝试将TextView子类化以实现我自己的滚动方法,但没有任何效果.
有没有办法实现这一目标?
顺便说一句....如果您使用例如htc sense或home desktop ++,有解决方案,但我想让其他不使用此功能的用户可以使用它
作为我项目的一部分,我有一个完美工作的小部件.然后我决定将公共代码(包括小部件)提取到库项目中.完成此操作后,除了小部件外,一切正常 它出现在可用于添加的小部件列表中,但是当我将它放在桌面上时,我得到的是这个Toast消息:"应用程序未安装在您的手机上".有人能说清楚这个吗?
配置和代码都没有改变.小部件文件(项目和库)中存在小部件定义,项目元文件包含绝对(包括路径)名称和所有权限.
我有一个Android appwidget,上面显示其他应用程序的图标.
我使用appInfo.loadIcon获取其他应用程序图标,然后使用setImageViewBitmap将其设置为小部件.
问题是,如果我的小部件上有太多图标,我会收到"FAILED BINDER TRANSACTION"错误.我知道它是从大小限制和解决它使用图像uri而不是位图本身.
是否有其他应用程序图标的可访问URI?
谢谢.
我正在使用Android Widget我的小部件就像下图, [上一页] 事件名称 [下一页]
上一页,接下来是widget上的按钮.所以我想点击next和prev按钮更新事件名称.在服务开始时,我加载了数据并将其存储在数组列表中.现在我想通过单击小部件上的next和prev按钮来遍历数组列表.
那么我怎样才能实现这一目标.请帮助我找到合适的解决方案.这是我的xml布局
<LinearLayout
android:id="@+id/lytWidget2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:orientation="horizontal" >
<Button
android:id="@+id/btnPreviousView"
android:layout_width="43dp"
android:layout_height="fill_parent"
android:layout_gravity="left|center"
android:background="@drawable/ic_leftarrow"
android:padding="5dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="52dp"
android:layout_weight="0.97"
android:text="Event Name" />
<Button
android:id="@+id/btnNextView"
android:layout_width="43dp"
android:layout_height="fill_parent"
android:layout_gravity="right|center_vertical"
android:background="@drawable/ic_rightarrow"
android:padding="5dip" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 类中没有setBackground()方法RemoteViews,所以我使用了以下解决方法:
FrameLayout为我的应用程序小部件创建了一个ImageView作为背景视图.ImageView使用setImageViewResource()方法更改了图像.不幸的是,当涉及9-patch drawables时,这种方法不起作用.当一个ImageView's android:src属性指向9-patch时 - 它也不起作用.有没有办法AppWidget用9-patch drawable以编程方式改变背景图像?提前致谢.
编辑 将9-patch设置为XML中的初始背景:
<ImageView
android:id="@+id/small_widget_layout_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_lime" />
Run Code Online (Sandbox Code Playgroud)
当我使用android:src="@drawable/background_lime"它不能正确拉伸图像,这段代码工作正常.以及从AppWidgetProvider onUpdate方法更改背景的代码:
views.setImageViewResource(R.id.small_widget_layout_bg,
R.drawable.backgroung_lime);
Run Code Online (Sandbox Code Playgroud)
这不会将图像拉伸为9补丁.
android background-image drawable nine-patch android-appwidget
这个问题几乎与Android相同-多个appWidgets播放不同的声音,但是我的代码无法正常工作。我在小部件ID中添加了一个意向附加内容,并带有日志语句来证明这一点,但是当我在多个小部件中单击一个小部件时,只有它的最后一个appWidgetId才有意义。添加第二个小部件后,第一个小部件的意图似乎正在改变。如果另一篇文章中的代码可以工作,那么我必须忽略一些东西,因为我相信我的设置方法几乎相同。
public class PhcaAppWidgetProvider extends AppWidgetProvider {
private static final String ACTION_CLICK = "com.skipmorrow.phca.PhcaAppWidgetProvider.WIDGET_CLICKED";
private final String widgetPageName = "_widget";
private static final String PREFS_NAME = "PHCA";
private static final String PREF_PREFIX_KEY = "prefix_";
private static String MY_DEBUG = "PhcaAppWidget";
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
Log.d(MY_DEBUG, "Provider.onUpdate");
}
@Override
public void onReceive(Context context, Intent intent) {
String intentAction = intent.getAction();
Log.d(MY_DEBUG, "Provider.onReceive(); action = " + intentAction);
Bundle extras = intent.getExtras();
// make …Run Code Online (Sandbox Code Playgroud) 有没有人经历过他们的app小部件未被列入ICS应用程序抽屉?
最初我开始使用FroYo及以下版本的应用程序,它支持app小部件就好了.随之而来的是Gingerbread和Honeycomb,这些也是如此.
如果我打开"小部件预览"应用程序,小部件将出现在模拟器的列表中,但是当您打开抽屉时,它不会与其他小部件一起列出.它确实出现在Honeycomb上.我不(也有其他人也没有)在我的Galaxy Nexus上看到它.
我尝试重新启动,因为我已经看到在初始安装后解决了一些人的问题.我也有一个主要的活动与action.MAIN/category.LAUNCHER意图过滤器,因为我有应用程序活动,这不是一个仅限小部件的项目类型.
我将在下面发布一些片段,如果需要更多,请告诉我.我的minSdkVersion为7,targetSdkVersion为15,项目属性的目标也是4.0.3.installLocation属性设置为auto.
AndroidManifest.xml中:
<receiver android:name=".AppWidget" android:label="@string/one_cell_widget_label">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<intent-filter>
<action android:name="com.frankcalise.h2droid.FORCE_WIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/one_cell_widget_settings" />
</receiver>
Run Code Online (Sandbox Code Playgroud)
one_cell_widget_settings.xml:
<appwidget-provider
xmlns:android="http://schemas.android.com/apk/res/android"
android:initialLayout="@layout/one_cell_widget"
android:minWidth="@dimen/one_cell_widget"
android:maxHeight="@dimen/one_cell_widget"
android:updatePeriodMillis="0" >
</appwidget-provider>
Run Code Online (Sandbox Code Playgroud)
one_cell_widget.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget_background"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/widget_margin"
android:background="@drawable/widget_background">
<TextView
android:id="@+id/widget_title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textColor="@android:color/black" />
<TextView
android:id="@+id/widget_amount_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/default_widget_amount"
android:textSize="12sp"
android:textColor="@color/amount_color" />
<TextView
android:id="@+id/widget_percent_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/default_widget_percent" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
然后显然我在AppWidget.java中实现了这个类
public class AppWidget extends AppWidgetProvider
Run Code Online (Sandbox Code Playgroud)
更新:
我今天早些时候发现的一条重要的logcat消息帮助我解决了这个问题:
06-01 14:41:31.606: E/AppsCustomizePagedView(199): Widget ComponentInfo{com.frankcalise.h2droid/com.frankcalise.h2droid.AppWidget} has invalid …Run Code Online (Sandbox Code Playgroud) 我的app小部件可以在多种模式下运行.对于这些模式中的每一种,我创建了一个RemoteViewsFactory.要在模式之间切换,我向我发送一个意图AppWidgetProvider.一旦接收到它,我创建RemoteViews并把它传递到AppWidgetManager的updateAppWidget().要设置RemoteViewsFactory集合视图,我调用RemoteViews' setRemoteAdapter():
rv.setRemoteAdapter(appWidgetId, R.id.widget_view_flipper, intent);
Run Code Online (Sandbox Code Playgroud)
R.id.widget_view_flipper是集合视图,intent用于RemoteViewsService构建适当的工厂.
编辑:我编辑了这个问题,因为我找出了最初描述的问题.现在,当我更换工厂时,getViewAt()新工厂的更改后会调用,但集合视图中的元素根本不会更新!怎么会发生这种情况?
现在我唯一想到的就是我可以在工厂更换后调用AppWidgetManager的notifyAppWidgetViewDataChanged,它会导致视图中的元素以丑陋的闪烁进行更新.
我有一个Android App小部件和小部件上的按钮.我已将更新时间段设置为30分钟,但我还想在每次触摸按钮时更新小部件.这是我的代码:
RemoteViews remoteV = new RemoteViews(context.getPackageName(), R.layout.widgetmenu);
Intent intentSync = new Intent(context, MessMenuWidgetProvider.class);
PendingIntent pendingSync = PendingIntent.getBroadcast(context,0, intentSync,0);
remoteV.setOnClickPendingIntent(R.id.imageButtonSync,pendingSync);
appWidgetManager.updateAppWidget(awID, remoteV);
Run Code Online (Sandbox Code Playgroud)
我已将更新时间设置为30分钟,因此每30分钟调用一次onUpdate()函数.我想要实现的是使用按钮手动调用onUpdate().但它没有发生.有帮助吗?
我使用以下代码创建了动态复选框:
XML:
<LinearLayout
android:id="@+id/layout_checkbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
的.java:
LinearLayout ll = (LinearLayout) findViewById(R.id.layout_checkbox);
ll.removeAllViews();
for (int i = 0; i < 10; i++) {
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
AppCompatCheckBox myCheckBox = new AppCompatCheckBox(getApplicationContext());
myCheckBox.setText(i);
myCheckBox.setTextColor(Color.parseColor("#FFFFFF"));
myCheckBox.setHintTextColor(Color.parseColor("#FFFFFF"));
myCheckBox.setTextSize(12);
myCheckBox.setId(i);
ll.addView(myCheckBox, lp);
}
Run Code Online (Sandbox Code Playgroud)
现在从上面的代码只有LOLLIPOP版本显示带有文本的复选框.对于以下LOLLIPOP版本,它仅显示Text但不显示复选框.
如果我将以下代码放在xml文件中,同样适用于所有设备:
<android.support.v7.widget.AppCompatCheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Testing"
android:buttonTint="@color/colorAccent"/>
Run Code Online (Sandbox Code Playgroud)
但我不能在xml中定义复选框,因为我必须动态创建它.
即使setButtonTintList不在下面工作LOLLIPOP
如何在下面的LOLLIPOP版本中显示Checkbox AppCompatCheckBox?
android ×10
android-4.0-ice-cream-sandwich ×1
checkbox ×1
drawable ×1
icons ×1
nine-patch ×1
xml ×1