3
我想以編程方式啓用和禁用4個UI按鈕。我正在使用Unity3D,但似乎無法使其工作。我錯過了什麼?我現在的嘗試是這樣的:如何啓用和禁用Android中的按鈕?
我LinearLayout
XML文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="right"
android:orientation="vertical" >
<com.BoostAR.Generic.TintedImageButton
android:id="@+id/helpButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/overlayButtonMargin"
android:src="@drawable/help"
android:visibility="visible" />
<com.BoostAR.Generic.TintedImageButton
android:id="@+id/refreshButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/overlayButtonMargin"
android:src="@drawable/refresh" />
<com.BoostAR.Generic.TintedImageButton
android:id="@+id/screenshotButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/overlayButtonMargin"
android:src="@drawable/photo" />
<com.BoostAR.Generic.LockButton
android:id="@+id/lockButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/overlayButtonMargin"
android:src="@drawable/unlocked" />
</LinearLayout>
我的代碼做了什麼:
private static final int[] AUGMENTED_UI_IDS = {
R.id.refreshButton, R.id.screenshotButton, R.id.lockButton
};
private void updateAugmentedUiVisibility()
{
final int visibility =
(mShouldShowAugmentedUI ? View.VISIBLE : View.INVISIBLE);
runOnUiThread(new Runnable() {
@Override
public void run() {
for (int id : AUGMENTED_UI_IDS) {
final View view = findViewById(id);
if (view == null) {
Log.e(LOG_TAG, "Failed to find view with ID: " + id);
} else {
Log.e(LOG_TAG, "Visibility: " + visibility);
view.setVisibility(visibility);
}
}
}
});
}
}
觀察:
聲明
Log.e(LOG_TAG, "Failed to find view with ID: " + id);
被調用。當我確實交叉引用了似乎很好的ID號碼。
你應該在這裏粘貼相關的代碼。 「打開和關閉這4個UI按鈕」是什麼意思?你想禁用/啓用它們? – codeMagic
我確實增加了這個問題。謝謝,是的,我想禁用並啓用它們。這就是我想要做的。 – karsnen
編輯嘗試和改進您的格式和您的語法。我還刪除了無關的介紹材料和*謝謝*。另外,我從pastebin導入了xml(請不要將您的部分問題鏈接到第三方網站)。 –