[APK在文本字段中使用setText后将无法编译

问题描述 投票:0回答:1

修改APK尝试使用户友好一些。有一个包含用户名和密码的登录屏幕以及一个服务器门户字段。现在,门户字段不再需要更改。因此,我想设置一个默认文本,以便用户不必键入完整的门户网站URL

当前看起来像这样

<EditText android:textSize="15.0dip" 
     android:textColor="@color/black" 
     android:textColorHint="@color/white" 
     android:id="@id/et_sever_url" 
     android:background="@drawable/selector_login_fields" 
     android:paddingLeft="20.0dip" 
     android:paddingRight="20.0dip" 
     android:focusable="true" 
     android:nextFocusUp="@id/et_password" 
     android:nextFocusDown="@id/bt_submit" 
     android:layout_width="fill_parent" 
     android:layout_height="50.0dip" 
     android:layout_marginLeft="25.0dip" 
     android:layout_marginTop="20.0dip" 
     android:layout_marginRight="25.0dip" 
     android:text="@string/serverurl" 
     android:hint="@string/serverurl" 
     android:maxLines="1" android:lines="1" 
     android:layout_below="@id/et_password" 
     android:layout_centerHorizontal="true"
     android:inputType="textUri" 
     android:textCursorDrawable="@null" 
     android:fontFamily="sans-serif" />

文本和提示仅将服务器url放入字段中,但仍必须手动输入。我尝试使用android:setText="@string/serverurl",但apk再次无法编译。

android apk settext
1个回答
0
投票

没有这样的edittext属性:android:setText =“ @ string / serverurl”

您要做的所有事情都是将默认字符串设置为您的editext,然后在xml中使用以下属性。

android:text="@string/serverurl"  

还删除了hint属性,因为设置了默认文本,所以您实际上并不需要该提示属性,因此不会显示提示。

还有第二个为什么要在下面的Java代码中执行此操作。

EditText edtServerUrl =findViewById(R.id.et_sever_url);
 edtServerUrl.setText(R.string.serverurl)

在活动的onCreate()方法中放入上面的代码。

© www.soinside.com 2019 - 2024. All rights reserved.