2016-08-03 12 views
1

私は問題があります: 私はいくつかのボタンがある "メインページ"を持っています。 RelativeLayoutを私のフラグメントに置き換えると、そのフラグメントのリスト上のボタンが表示されます。私はフラグメントを開始した後、ボタンを見えなくするにはどうすればいいですか? Here is a Screenshot. All yellow marked are from the MainActivity and the list behind them is from the fragment. [LINK]フラグメントはMainActivityのボタンの下にあります

重要コード:

public boolean onNavigationItemSelected(MenuItem item) { 
    // Handle navigation view item clicks here. 
    int id = item.getItemId(); 

    if (id == R.id.nav_functions) { 
     startFragment(FunctionsFragment.newInstance(1), "TagFunctions"); 
     Log.d("SMSAT", "nav_functions pressed"); 
    } else if (id == R.id.nav_macro) { 

    } else if (id == R.id.nav_settings) { 

    } else if (id == R.id.nav_platzhalter) { 

    } else if (id == R.id.nav_contact) { 

    } else if (id == R.id.nav_share) { 

    } 

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
    drawer.closeDrawer(GravityCompat.START); 
    return true; 
} 

private void startFragment(Fragment fragment, String tag){ 


    FragmentManager fragmentManager = getSupportFragmentManager(); 
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 
    fragmentTransaction.replace(R.id.main_fragment_container, fragment, tag).commit(); 

    Log.d("SMSAT", "startFragment() ausgeführt"); 

} 

?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:context="de.mika.smsantitheft.MainActivity" 
tools:showIn="@layout/app_bar_main" 
android:id="@+id/main_relative_layout"> 


<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:text="@string/home_sms_commands" 
    android:id="@+id/textViewSmsBefehleStatus" 
    android:layout_marginTop="33dp" 
    android:layout_marginLeft="27dp" 
    android:layout_marginStart="27dp" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 

    <ToggleButton 
    android:layout_width="140dp" 
    android:layout_height="wrap_content" 
    android:text="New ToggleButton" 
    android:id="@+id/toggleButton" 
    android:textOn="@string/aktivated" 
    android:textOff="@string/deaktivated" 
    android:layout_below="@+id/textViewSmsBefehleStatus" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" 
    android:layout_marginRight="30dp" 
    android:layout_marginEnd="30dp" /> 

    <Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/menu_functions" 
    android:id="@+id/button" 
    android:layout_below="@+id/toggleButton" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginTop="49dp" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" /> 

    <Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/menu_macros" 
    android:id="@+id/button2" 
    android:layout_below="@+id/button" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" /> 

    <Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/menu_settings" 
    android:id="@+id/button3" 
    android:layout_below="@+id/button2" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" /> 

    <Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/menu_contact" 
    android:id="@+id/button5" 
    android:layout_below="@+id/button3" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" /> 

    <Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/menu_recommend" 
    android:id="@+id/button4" 
    android:layout_below="@+id/button5" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" /> 

    <FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/main_fragment_container"></FrameLayout> 

    </RelativeLayout> 

はあなたの助けをありがとう!

答えて

0

すべてのボタンをレイアウトに配置します。レイアウトの可視性全体を変更します。

0

startFragmentでボタンを非表示に設定しましたか?

Button button = (Button) findViewById(R.id.button_location); 
button.setVisibility(View.GONE); 
+0

私はそれを試してみます。ありがとう – Mika119

0

置き換え以外の方法を使用してください。

それでも問題が解決しない場合は、appliactionのテーマをandroid:Theme.Material.Lightに設定してみてください。

それでも問題が解決しない場合は、XML上で新しいフラグメントの背景を白に設定してください。それはあなたのノートブックの別のシートのような気分になります。

関連する問題