2016-06-21 25 views
0

所以我有一個活動及其XML文件,這兩個文件都不包含任何與晶圓廠有關的事情(因爲我已經擦除晶圓廠)。然而,當我構建並運行應用程序時,一個「鬼屋」仍然出現 - 我甚至無法點擊它,它只是坐在角落裏,我不知道如何刪除它。FAB出現在不應該有FAB的活動中

活動:

package example.com.musicapptest; 

import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentManager; 
import android.support.v4.app.FragmentPagerAdapter; 
import android.support.v4.view.ViewPager; 
import android.support.v7.app.AppCompatActivity; 
import android.support.v7.widget.Toolbar; 
import android.view.LayoutInflater; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.Button; 
import android.widget.ProgressBar; 
import android.widget.TextView; 

public class HostMainPage extends AppCompatActivity { 

/** 
* The {@link android.support.v4.view.PagerAdapter} that will provide 
* fragments for each of the sections. We use a 
* {@link FragmentPagerAdapter} derivative, which will keep every 
* loaded fragment in memory. If this becomes too memory intensive, it 
* may be best to switch to a 
* {@link android.support.v4.app.FragmentStatePagerAdapter}. 
*/ 
private SectionsPagerAdapter mSectionsPagerAdapter; 

/** 
* The {@link ViewPager} that will host the section contents. 
*/ 
private ViewPager mViewPager; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_host_main_page); 
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 
    // Create the adapter that will return a fragment for each of the three 
    // primary sections of the activity. 
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); 

    // Set up the ViewPager with the sections adapter. 
    mViewPager = (ViewPager) findViewById(R.id.container); 
    mViewPager.setAdapter(mSectionsPagerAdapter); 
} 


@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.menu_main, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 

    //noinspection SimplifiableIfStatement 
    if (id == R.id.action_settings) { 
     return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 

/** 
* A placeholder fragment containing a simple view. 
*/ 
public static class PlaceholderFragment extends Fragment { 
    /** 
    * The fragment argument representing the section number for this 
    * fragment. 
    */ 
    private static final String ARG_SECTION_NUMBER = "section_number"; 

    public PlaceholderFragment() { 
    } 

    /** 
    * Returns a new instance of this fragment for the given section 
    * number. 
    */ 
    public static PlaceholderFragment newInstance(int sectionNumber) { 
     PlaceholderFragment fragment = new PlaceholderFragment(); 
     Bundle args = new Bundle(); 
     args.putInt(ARG_SECTION_NUMBER, sectionNumber); 
     fragment.setArguments(args); 
     return fragment; 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     //Linking up values in fragment_main.xml to the MainActivity 
     View rootView = inflater.inflate(R.layout.fragment_host_main_page, container, false); 
     TextView splashTitleView = (TextView) rootView.findViewById(R.id.host_splash_title); 
     TextView splashBodyView = (TextView) rootView.findViewById(R.id.host_splash_body); 
     ProgressBar splashProgress = (ProgressBar) rootView.findViewById(R.id.host_splash_progres); 
     Button hostButton = (Button) rootView.findViewById(R.id.host_start_button); 
     hostButton.setVisibility(View.GONE); 

     /* 
      Setting up which splash page will be displayed as the user progresses throughout the welcome splash page 
     */ 
     if (getArguments().getInt(ARG_SECTION_NUMBER) == 1) { 
      splashTitleView.setText("Host Welcome"); 
      splashBodyView.setText("Filler Text"); 
      splashProgress.setProgress(20); 
     } else if (getArguments().getInt(ARG_SECTION_NUMBER) == 2) { 
      splashTitleView.setText("Create a Party ID"); 
      splashBodyView.setText("Filler Text"); 
      splashProgress.setProgress(40); 
     } else if (getArguments().getInt(ARG_SECTION_NUMBER) == 3) { 
      splashTitleView.setText("People Joint"); 
      splashBodyView.setText("Filler Text"); 
      splashProgress.setProgress(60); 
     } else if (getArguments().getInt(ARG_SECTION_NUMBER) == 4) { 
      splashTitleView.setText("Vote, Suggest, or View Leaderboards"); 
      splashBodyView.setText("Filler Text"); 
      splashProgress.setProgress(80); 
     } 
     else if (getArguments().getInt(ARG_SECTION_NUMBER) == 5) { 
      hostButton.setVisibility(View.VISIBLE); 
      splashTitleView.setText("Start Hosting"); 
      splashBodyView.setText("Filler Text"); 
      splashProgress.setProgress(100); 
     } 
     //Default frag if for some reason there is an IndexOutOfBoundsException() 
     else { 
      splashTitleView.setText("Get Started Fragment"); 
      splashBodyView.setText("Filler Text"); 
      splashProgress.setProgress(100); 
     } 

     return rootView; 
    } 
} 

/** 
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to 
* one of the sections/tabs/pages. 
*/ 
public class SectionsPagerAdapter extends FragmentPagerAdapter { 

    public SectionsPagerAdapter(FragmentManager fm) { 
     super(fm); 
    } 

    @Override 
    public Fragment getItem(int position) { 
     // getItem is called to instantiate the fragment for the given page. 
     // Return a PlaceholderFragment (defined as a static inner class below). 
     return PlaceholderFragment.newInstance(position + 1); 
    } 

    @Override 
    public int getCount() { 
     // Show 5 total pages. 
     return 5; 
    } 

    @Override 
    public CharSequence getPageTitle(int position) { 
     switch (position) { 
      case 0: 
       return "SECTION 1"; 
      case 1: 
       return "SECTION 2"; 
      case 2: 
       return "SECTION 3"; 
      case 3: 
       return "SECTION 4"; 
      case 4: 
       return "SECTION 5"; 
     } 
     return null; 
    } 
} 

}

和XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="example.com.musicapptest.HostMainPage$PlaceholderFragment"> 

<TextView 
    android:id="@+id/host_splash_title" 
    android:layout_width="300dp" 
    android:layout_height="100dp" 
    android:gravity="center" 
    android:layout_marginTop="22dp" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true"/> 

<TextView 
    android:layout_width="500dp" 
    android:layout_height="100dp" 
    android:gravity="center" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:id="@+id/host_splash_body" 
    android:layout_below="@id/host_splash_title" 
    android:layout_centerHorizontal="true" 
    android:layout_alignParentEnd="true" 
    android:layout_marginTop="20dp" /> 

<ProgressBar 
    style="?android:attr/progressBarStyleHorizontal" 
    android:layout_width="300dp" 
    android:layout_height="wrap_content" 
    android:id="@+id/host_splash_progres" 
    android:layout_marginTop="48dp" 
    android:layout_below="@+id/host_splash_body" 
    android:layout_alignStart="@+id/host_splash_title" /> 

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/host_start_button" 
    android:id="@+id/host_start_button" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginBottom="68dp" /> 

</RelativeLayout> 

這裏是一個圖像我所看到供參考:

Ghost FAB

謝謝!

+0

這個XML可能是你的'片段'和'活動'? – snachmsm

回答

0

您正在查看錯誤的佈局XML文件。您正在佈局中找到工具欄:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 

但您粘貼的佈局中沒有工具欄。您必須擁有另一個佈局文件,名爲activity_host_main_page.xml,其中包含FAB。