Android主屏幕小部件与失败的EditText [英] Android Home Screen Widget Failing with EditText

查看:146
本文介绍了Android主屏幕小部件与失败的EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我添加一个EditText小部件到我的主屏幕小部件的布局(混淆术语如何小部件被使用两次在Android词汇: - /),我收到了问题加载控件错误框

下面是我试图布局;如果您删除的EditText,它的工作原理...

<


  

RelativeLayout的
          机器人:layout_width =FILL_PARENT
          机器人:layout_height =FILL_PARENT
          的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>

 <按钮
                机器人:ID =@ + ID / button_generate
                机器人:layout_width =54px
                机器人:layout_height =54px
                机器人:文字=生成
                机器人:TEXTSIZE =10SP
                机器人:比重=中心
                机器人:layout_alignParentTop =真
                机器人:layout_toRightOf =@ + ID / edittext_key>
        < /按钮>        <的TextView
                机器人:ID =@ + ID / textview_hash
                机器人:layout_width =960x75像素
                机器人:layout_height =×45像素
                机器人:文字=密码
                机器人:TEXTSIZE =11SP
                机器人:重力=左
                机器人:layout_alignParentTop =真
                机器人:layout_toLeftOf =@ + ID / edittext_key>
        < / TextView的>        <的EditText
                机器人:ID =@ + ID / edittext_data2
                机器人:layout_width =200像素
                机器人:layout_height =50像素
                机器人:TEXTSIZE =12SP
                机器人:layout_marginTop =20像素
                机器人:layout_alignParentTop =真
                机器人:layout_centerHorizo​​ntal =真正的>
        < /&的EditText GT; < / RelativeLayout的>


现在,谷歌的搜索主屏幕小部件有一个EditText,所以这显然是法律实施。为什么这有什么想法是不工作?


解决方案

Widget使用RemoteViews,只支持一定数量的用户界面元素。不包括的EditText。 Android的<一个href=\"http://developer.android.com/intl/de/guide/topics/appwidgets/index.html#CreatingLayout\">documentation显示了支持。

在谷歌搜索主页屏幕小部件实际上使用一个TextView。 (<一href=\"http://android.git.kernel.org/?p=platform/packages/apps/Launcher.git;a=blob;f=res/layout/widget_search.xml;h=f8c59fe314c18cf8a3213f144c8ca35cdfbb77c6;hb=HEAD\">Source code )

Whenever I add an EditText widget to the layout of my home screen widget (confusing how the term "widget" is being used twice in the Android lexicon :-/ ), I receive the "Problem Loading Widget" error box.

Here is the layout I'm attempting; if you remove the EditText, it works...

<

RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">

        <Button
                android:id="@+id/button_generate"
                android:layout_width="54px"
                android:layout_height="54px"
                android:text="Generate"
                android:textSize="10sp"
                android:gravity="center"
                android:layout_alignParentTop="true"
                android:layout_toRightOf="@+id/edittext_key">
        </Button>   

        <TextView
                android:id="@+id/textview_hash"
                android:layout_width="75px"
                android:layout_height="45px"
                android:text="Password"
                android:textSize="11sp"
                android:gravity="left"
                android:layout_alignParentTop="true"
                android:layout_toLeftOf="@+id/edittext_key">
        </TextView>

        <EditText
                android:id="@+id/edittext_data2"
                android:layout_width="200px"
                android:layout_height="50px"
                android:textSize="12sp"
                android:layout_marginTop="20px"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true">
        </EditText> </RelativeLayout>

Now, the Google Search home screen widget has an EditText, so it's obviously legal to implement. Any thoughts on why this is not working?

解决方案

Widgets use RemoteViews, which only support a certain number of UI elements. EditText is not included. The Android documentation shows which are supported.

The Google Search home screen widget actually uses a TextView. (Source code)

这篇关于Android主屏幕小部件与失败的EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆