Android 工具栏在片段中是半透明的,并且不';不要对轻叩声做出反应
我制作了一个具有导航抽屉功能的应用程序。我在主要内容中有一个片段,当用户想要导航时,替换该片段。它在SDK级别21以上工作得非常好。低于21时,工具栏将变为半透明,并且不会对任何可滚动的新工具栏绘制导航抽屉的点击做出响应。对于其他片段中的不可滚动视图,它可以完美地工作。我希望工具栏是不透明的,并对点击做出响应,但似乎找不到方法 我的主要活动是OnCreate:Android 工具栏在片段中是半透明的,并且不';不要对轻叩声做出反应,android,android-fragments,Android,Android Fragments,我制作了一个具有导航抽屉功能的应用程序。我在主要内容中有一个片段,当用户想要导航时,替换该片段。它在SDK级别21以上工作得非常好。低于21时,工具栏将变为半透明,并且不会对任何可滚动的新工具栏绘制导航抽屉的点击做出响应。对于其他片段中的不可滚动视图,它可以完美地工作。我希望工具栏是不透明的,并对点击做出响应,但似乎找不到方法 我的主要活动是OnCreate: @Override protected void onCreate(Bundle savedInstanceState)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
imageView = (ImageView) findViewById(R.id.nav_drawer_image);
assert getSupportActionBar() != null;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("Home");
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
NavDrawerFragment navDrawerFragment = (NavDrawerFragment) getFragmentManager()
.findFragmentById(R.id.nav_drawer_fragment);
navDrawerFragment.setup(R.id.nav_drawer_fragment, (DrawerLayout) findViewById(R.id.drawer_layout), toolbar);
recyclerView = (RecyclerView) findViewById(R.id.nav_drawer_recycler_view);
Adapter adapter = new Adapter(this, getData());
adapter.setClickListener(this);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().add(R.id.frame_for_fragments, new HomeFragment()).commit();
if(scheduleReturnFlag) {
toolbar.setTitle("Schedule");
getFragmentManager().beginTransaction()
.replace(R.id.frame_for_fragments, new ScheduleFragment()).commit();
selected_item_number = 4;
}
}
我用于替换片段的方法:
@Override
public void onItemClick(View view, int position) {
switch (position) {
case 0:
if (selected_item_number == 0)
break;
toolbar.setTitle("Home");
getFragmentManager().beginTransaction()
.replace(R.id.frame_for_fragments, new HomeFragment()).commit();
selected_item_number = 0;
break;
case 1:
if (selected_item_number == 1)
break;
toolbar.setTitle("Attractions");
getFragmentManager().beginTransaction()
.replace(R.id.frame_for_fragments, new AttractionsFragment()).commit();
selected_item_number = 1;
break;
case 2:
if (selected_item_number == 2)
break;
toolbar.setTitle("IDPT");
getFragmentManager().beginTransaction()
.replace(R.id.frame_for_fragments, new IDPTFragment()).commit();
selected_item_number = 2;
break;
case 3:
if (selected_item_number == 4)
break;
toolbar.setTitle("Schedule");
getFragmentManager().beginTransaction()
.replace(R.id.frame_for_fragments, new ScheduleFragment()).commit();
selected_item_number = 4;
break;
case 4:
if (selected_item_number == 5)
break;
toolbar.setTitle("Gallery");
getFragmentManager().beginTransaction()
.replace(R.id.frame_for_fragments, new GalleryFragment()).commit();
selected_item_number = 5;
break;
case 5:
if (selected_item_number == 6)
break;
toolbar.setTitle("The Team");
getFragmentManager().beginTransaction()
.replace(R.id.frame_for_fragments, new TeamFragment()).commit();
selected_item_number = 6;
break;
case 6:
if (selected_item_number == 7)
break;
toolbar.setTitle("About");
getFragmentManager().beginTransaction()
.replace(R.id.frame_for_fragments, new AboutFragment()).commit();
selected_item_number = 7;
break;
case 7:
if (selected_item_number == 8)
break;
toolbar.setTitle("Sponsors");
getFragmentManager().beginTransaction()
.replace(R.id.frame_for_fragments, new SponsorsFragment()).commit();
selected_item_number = 8;
break;
case 8:
if (selected_item_number == 9)
break;
toolbar.setTitle("Contact Us");
getFragmentManager().beginTransaction()
.replace(R.id.frame_for_fragments, new ContactDetailsFragment()).commit();
selected_item_number = 9;
break;
}
drawerLayout.closeDrawers();
}
我的ScrollableFragment:
package in.djtrinity.www.trinity;
import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* A simple {@link Fragment} subclass.
*/
public class TeamFragment extends Fragment {
public TeamFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_team, container, false);
}
}
<FrameLayout 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"
tools:context="in.djtrinity.www.trinity.AboutFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_marginTop="48dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center"
android:text="Chairperson"
android:textColor="@color/colorPrimary"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:text="Anmol Gandhi"
android:textSize="15sp" />
</LinearLayout>
</ScrollView>
</FrameLayout>
可滚动片段:
package in.djtrinity.www.trinity;
import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* A simple {@link Fragment} subclass.
*/
public class TeamFragment extends Fragment {
public TeamFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_team, container, false);
}
}
<FrameLayout 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"
tools:context="in.djtrinity.www.trinity.AboutFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_marginTop="48dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center"
android:text="Chairperson"
android:textColor="@color/colorPrimary"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:text="Anmol Gandhi"
android:textSize="15sp" />
</LinearLayout>
</ScrollView>
</FrameLayout>