2011-12-14 1 views
0

버튼 가시성에 문제가 있습니다. 나는 제목 표시 줄에서 2 버튼을 가지고 있습니다. 그들 중 하나가 편집 중 하나가 완료되었습니다. 먼저 편집 버튼을 클릭하고 편집 버튼을 클릭하면 버튼 가시성이 false가되고 버튼 가시성이 완료됩니다.제목 표시 줄의 가시성 단추를 프로그래밍 방식으로 변경 하시겠습니까?

나는 그들의 ID를 xml에서 얻었고, 그 중 하나를 클릭하면 나는 가시성을 바꾸고 싶지만 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에 : 당신의 LinearLayout의 방향 매개 변수 :

<?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> 
+1

이런 종류의 동작을 수행하려면 작업 표시 줄을 사용하십시오. 액션 바는 Android 3.0 이상에서 기본으로 제공되며 이전 버전의 Android (예 : ActionBarSherlock)에서 액션 바를 제공하기위한 다양한 라이브러리가 있습니다. – CommonsWare

답변

0

첫째, 당신은 안드로이드를 놓치고있어.

edit.setVisibility(View.GONE); 
done.setVisibiluty(View.VISIBLE); 

과 반대 표시되지 않습니다 View.INVISIBLE으로 .. 버튼을 다시 버튼을 편집 변경하지만 여전히 사용 : 당신이 편집 사이에서 변경 및 수행하려는 경우

둘째, 당신은이 작업을 수행 할 수 있습니다 그것이 있었던 공간.

0

setFeatureInt은 제목에 대한 리소스 ID를 설정하기 만하므로 레이아웃 리소스의 새로운 팽창이 발생하며 FrameLayout이라는 id/title_container 시스템에 배치됩니다. 이클립스에서 Hierarchy Viewer를 사용하여 검사 할 수 있습니다.

기본적으로 두 개의 기본 레이아웃 인스턴스가 있습니다. 한 세트는 내용보기 (제목 아래)로 설정되고 다른 세트는 제목으로 설정됩니다. findViewById에 전화하면 콘텐츠보기에서 ID와 일치하는보기 만 찾습니다. 즉, 검색하는 editdone 버튼이 콘텐츠보기에있는 버튼이라는 의미입니다.

는 제목 영역의 버튼에 액세스하려면, 당신이 사용할 수있는

View v = getWindow().getDecorView(); 
    edit=(Button)v.findViewById(R.id.edit); 
    done=(Button)v.findViewById(R.id.done); 
    edit.setVisibility(View.INVISIBLE); 

이 따라서 문제를 해결, 윈도우뿐 아니라 콘텐츠 뷰의 전경 구조를 검색합니다.

관련 문제