非常基本的问题,但是,如果你把它放在变量之前,那么"最终"会做什么,例如下面...
final EditText myTextField = (EditText) findViewById(R.id.myTextField);
Run Code Online (Sandbox Code Playgroud)
怎么final
办?
当您建立共享偏好时,例如下面...
public static final String PREFS_HI = "MyPrefsFile";
Run Code Online (Sandbox Code Playgroud)
您可以像平常一样从其他活动中访问它吗?
SharedPreferences settings = getSharedPreferences(PREFS_HI, 0);
Run Code Online (Sandbox Code Playgroud)
或者您是否有必要做的事情来访问偏好?
我猜这很简单,但由于某种原因我无法弄清楚.那么,你如何从两个数字中选择一个随机整数.我想随机选择1和2之间的整数.
我正在使用此代码来更改android主页的壁纸
WallpaperManager wm = WallpaperManager.getInstance(this);
wm.setBitmap(myBitmap);
Run Code Online (Sandbox Code Playgroud)
我想将背景设置为drawable.这可能吗?
/* */ public static void printJoinChat(Player player) {
/* 41 */ FileConfiguration kitConfig = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), "kit.yml"));
/* 42 */ List kitname = kitConfig.getStringList("KITS");
/* */
/* 44 */ String vipkit = "";
/* 45 */ String norkit = "";
/* 46 */ for (String name : kitname) {
/* 47 */ ConfigurationSection kit = kitConfig.getConfigurationSection(name.toLowerCase());
/* 48 */ if (kit.getBoolean("VIP")) {
/* 49 */ if (vipkit == "")
/* 50 */ vipkit = name;
/* */ else {
/* …
Run Code Online (Sandbox Code Playgroud) <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:text="Title"
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30px"
android:textStyle="bold"
>
</TextView>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="60px">
<Button
android:text="Choose a Story"
android:id="@+id/choose"
android:layout_width="150px"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="1px">
</Button>
<Button
android:text="Info"
android:id="@+id/info"
android:layout_width="150px"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="1px">
</Button>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
在这段代码中,正如您所看到的,在线性布局中有一个标题,2个线性布局和2个按钮.我要做的是将2个按钮居中.无论我做什么,我都无法让2个按钮在底部居中,高度为60px.
最后,我试图使文本在垂直和水平方向上居中,并使底部的2个按钮水平居中.我需要改变什么?
下面是布局编辑器中的图片.