Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何在android中获取和设置字符串资源值大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我已声明一个字符串:

<String name="Please">Please SELEct</String>

在res / values / Strings.xml中.现在我想访问这个String值,但我能得到的东西可以直到id不值如下:

int i = findViewById(R.String.PleasE);

但我想要的只是字符串Please的值.

谢谢你的所有答案,但我的问题有点大

我想做的只是用app_name显示日期

从你所有的答案我可以得到app_name字符串
但我是否可以设定
此app_name包含当前日期

<String name="app_name">My app</String>

而且我也是这样设置我的

@H_19_7@my app(in Left alignment) Date (in right aligment)

并且在第一个活动开始时我想设置app_name而不是每个活动;

我认为这可能有用,让我尝试一下

setresource().setString(R.String.PleasE);

但没有setresource()方法对不起.

解决方法@H_262_43@
你不能设置一个字符串,它的静态,并且不能在运行时更改,你想要做的就是这样

Calendar cal = Calendar.geTinstance();
        String date = cal.get(Calendar.DAY_OF_MONTH) + "/" + cal.get(Calendar.MONTH) + "/" + cal.get(Calendar.YEAR);
        settitle(datE);

你试图将标题设置为日期吗?

要拥有两个标题,有点困难,首先需要布局,调用此custom_title_1

这是该布局的xml代码

<RelativeLayout xmlns:android="http://scheR_786_11845@as.android.com/apk/res/android" android:id="@+id/screen"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:orientation="vertical">
    <TextView android:id="@+id/left_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="@String/custom_title_left" />
    <TextView android:id="@+id/right_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentright="true"
        android:text="@String/custom_title_right" />
</RelativeLayout>

然后在调用UI之前在代码中,您需要调用它:

requestWindowFeature(Window.FEATURE_CUSTOM_titlE);

然后设置内容视图

然后调用它来设置标题

getWindow().setFeatureInt(Window.FEATURE_CUSTOM_titlE,R.layout.custom_title_1);

现在您可以找到两个textView并设置文本:

TextView leftText = (TextView) findViewById(R.id.left_text);
TextView rightText = (TextView) findViewById(R.id.right_text);

Calendar cal = Calendar.geTinstance();
String date = cal.get(Calendar.DAY_OF_MONTH) + "/" + cal.get(Calendar.MONTH) + "/" + cal.get(Calendar.YEAR);
String app_name = getString(R.String.app_Name);
leftText.setText(app_Name);
rightText.setText(datE);

大佬总结

以上是大佬教程为你收集整理的如何在android中获取和设置字符串资源值全部内容,希望文章能够帮你解决如何在android中获取和设置字符串资源值所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。