我有一個問題按鈕的可見性。我有2個來自標題欄的按鈕。其中一個編輯,其中一個完成。首先,我想看到只是編輯按鈕,當我點擊編輯按鈕,編輯按鈕的可見性將是錯誤的,並完成按鈕可見性真實。以編程方式從標題欄更改可見性按鈕?
我從XML獲得他們的ID,當我點擊其中一個我想改變可見性,但edit.setVisibility();它不工作。怎麼了?我可以看到編輯按鈕。我想以編程方式更改按鈕的可見性。
任何人都可以有任何想法嗎?
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final boolean customTitle = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
edit=(Button)findViewById(R.id.edit);
done=(Button)findViewById(R.id.done);
edit.setVisibility(View.INVISIBLE);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.main);
if (customTitle) {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.main);
}
的main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:id="@+id/edit"
android:layout_width="57px"
android:layout_height="wrap_content"
android:text="edit"/>
<Button android:id="@+id/done"
android:layout_width="57px"
android:layout_height="wrap_content"
android:text="done"/>
</LinearLayout>
請對這種行爲使用操作欄。操作欄在Android 3.0+上是原生的,並且有多種庫用於在較早版本的Android上提供操作欄(例如,ActionBarSherlock)。 – CommonsWare 2011-12-14 14:00:27