My Android aplikacji uruchamia się BeginActivity który jest podklasą SherlockFragmentActivity i pokazuje to pierwszy widok, używając:Fragment jest przezroczysta i wykazuje aktywność poniżej
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null) {
Fragment f = LoginFragment.newInstance();
getSupportFragmentManager()
.beginTransaction()
.add(android.R.id.content, f, "loginfragment")
.attach(f)
.commit();
}
}
LoginFragment pokazuje widok takiego:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.login, container, false);
// Get pointers to text views
usernameField = (EditText) v.findViewById(R.id.usernameLog);
passwordField = (EditText) v.findViewById(R.id.passwordLog);
progressBar = (ProgressBar) v.findViewById(R.id.progressBarLog);
// Set button click listeners for both buttons
Button b = (Button) v.findViewById(R.id.loginButton);
b.setOnClickListener(this);
return v;
}
po kliknięciu logowania wyświetlam widok listy w następujący sposób:
BeginActivity top = (BeginActivity) getActivity();
Fragment f = OfferListFragment.newInstance();
top.getSupportFragmentManager()
.beginTransaction()
.add(android.R.id.content, f, "offerList")
.addToBackStack(f.getClass().getSimpleName())
.commit();
oraz wreszcie OfferListFragment wyświetla jego widok tak:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.offers, container, false);
return v;
}
Teraz problem mam, jest to, że ostateczna OfferListFragment wydaje się być przejrzyste i widzę ekran logowania poniżej niego. Używam Theme.Sherlock, który ma czarne tło. Czy powinienem ręcznie ustawiać widoki tła na czarny? A może czarny w temacie może być dostosowywany przez użytkownika w systemie? (Nie jestem użytkownikiem Androida).
Dzięki
Czy chcesz całkowicie usunąć 'LoginFragment' z' BeginActivity' podczas wyświetlania 'OfferListFragment'? –
Nieszczególnie. Użytkownik powinien mieć możliwość kliknięcia przycisku Wstecz, aby wrócić do niego. – Darren
OK bro.Nie jestem pewien, ale czy próbowałeś używając 'replace (int, android.app.Fragment)' z klasy 'FragmentTransaction'? –