gpt4 book ai didi

java - 使用 BottomBar 可以防止 fragment 打开?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:10:55 25 4
gpt4 key购买 nike

我正在使用支持库添加一个类似于 Material Design 的底栏。底部栏效果很好,但似乎如果我显示栏,如果我尝试从我的自定义适配器打开任何 fragment , fragment 不会打开......或者它可能在我的主布局后面打开?我不知道如何解决这个问题。下面是我的代码。

我已经在 SO 和网络上阅读了更多帖子,我认为这与正确加载但位于底部栏下方或旁边的 fragment 有关......这就是它不可见的原因?为什么会这样?是因为底栏有LinearLayout吗?我将它定义为一个菜单,所以我不确定我是否可以将它控制为一个 LinearLayout....

设置底部栏,此方法从我的 Activity 的 onCreate 调用:

public void setupBottomToolbar(Bundle savedInstanceState) {
mBottomBar = BottomBar.attach(MainActivity.this, savedInstanceState);
mBottomBar.setItems(R.menu.bottombar_menu);

mBottomBar.setOnMenuTabClickListener(new OnMenuTabClickListener() {
@Override
public void onMenuTabSelected(@IdRes int menuItemId) {
if (menuItemId == R.id.toolbar_jobs) {

} else if (menuItemId == R.id.toolbar_messages) {

} else if (menuItemId == R.id.toolbar_recentJobs) {

} else if (menuItemId == R.id.toolbar_employerPools) {

}
}

@Override
public void onMenuTabReSelected(@IdRes int menuItemId) {
if (menuItemId == R.id.toolbar_jobs) {
// The user reselected item number one, scroll your content to top.
} else if (menuItemId == R.id.toolbar_messages) {

} else if (menuItemId == R.id.toolbar_employerPools) {

} else if (menuItemId == R.id.toolbar_recentJobs) {

}
}
});

// Setting colors for different tabs when there's more than three of them.
// You can set colors for tabs in three different ways as shown below.
mBottomBar.getBar().setBackgroundColor(getResources().getColor(R.color.laborswipe_darkgray));
mBottomBar.setActiveTabColor(getResources().getColor(R.color.laborswipe_lightgray));

// Make a Badge for the second tab, with red background color and a value of "13".
BottomBarBadge unreadMessages = mBottomBar.makeBadgeForTabAt(1, getResources().getColor(R.color.laborswipe_orange), 5);

// Control the badge's visibility
unreadMessages.show();
//unreadMessages.hide();

// Change the displayed count for this badge.
//unreadMessages.setCount(4);

// Change the show / hide animation duration.
unreadMessages.setAnimationDuration(200);

// If you want the badge be shown always after unselecting the tab that contains it.
unreadMessages.setAutoShowAfterUnSelection(true);

// If you don't want this badge to be hidden after selecting the tab contains it.
unreadMessages.setAutoShowAfterUnSelection(false);
}

在我的适配器中,我尝试在您单击按钮时打开 fragment ,如下所示:

holder.desc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(context, "Open Description", Toast.LENGTH_SHORT).show();

JobDescFragment firstFragment = new JobDescFragment();
((MainActivity)context).getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_container, firstFragment).commit();
}
});

如果我在 Activity 的 onCreate 中注释掉对 setupBottomToolbar() 的调用,该 fragment 可以正常打开...但这意味着我没有底部栏...

我错过了什么?必须有一种方法可以使用底栏并打开 fragment 吗?

谢谢!

编辑:

这是我的 Activity 的顶部。

public class MainActivity extends AppCompatActivity {

private ArrayList<String> swipecardsList;
private ArrayList<Job> jobList = new ArrayList<Job>();
private JobAdapter arrayAdapter; //arrayadapter
private BottomBar mBottomBar;
SharedPreferences settings;

@InjectView(R.id.frame) SwipeFlingAdapterView flingContainer;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

//Remove title bar
//this.requestWindowFeature(Window.FEATURE_NO_TITLE);

//color the notification bar with our company colors
Window window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(this.getResources().getColor(R.color.laborswipe_notificationbar));

//remove title from action bar and add the logo to the top left of the action bar
setupTopToolbar();

setContentView(R.layout.activity_main);
ButterKnife.inject(this);

//set up the bottom toolbar using the roughike library to mimic android material design
setupBottomToolbar(savedInstanceState);

我的适配器:

public class JobAdapter extends ArrayAdapter<Job> {
private final Context context;
private final ArrayList<Job> jobs;
private final int layoutResourceId;
private final SwipeFlingAdapterView flingContainer;
private boolean isExpanded = false;

public JobAdapter(Context context, int layoutResourceId, ArrayList<Job> jobs, SwipeFlingAdapterView flingContainer) {
super(context, layoutResourceId, jobs);
this.context = context;
this.jobs = jobs;
this.layoutResourceId = layoutResourceId;
this.flingContainer = flingContainer;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
final ViewHolder holder;
String pay, hrs;
final Bundle fragmentParams = new Bundle();

LayoutInflater inflater = LayoutInflater.from(context);

if (view == null) {
view = inflater.inflate(layoutResourceId, parent, false);

holder = new ViewHolder();
holder.title = (TextView)view.findViewById(R.id.tv_jobTitle);
holder.desc = (TextView) view.findViewById(R.id.tv_JobDesc);

view.setTag(holder);
} else {
holder = (ViewHolder)view.getTag();
}

Job j = jobs.get(position);

holder.title.setText(j.getJobTitle());
holder.desc.setText(j.getDescription());

//when user clicks apply, swipe the card right
holder.apply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Open up a fragment to display the entire job description
Toast.makeText(context, "Applied", Toast.LENGTH_SHORT).show();
flingContainer.getTopCardListener().selectRight();
}
});

//when user clicks dismiss, swipe the card left
holder.dismiss.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Open up a fragment to display the entire job description
Toast.makeText(context, "Dismissed", Toast.LENGTH_SHORT).show();
flingContainer.getTopCardListener().selectLeft();
}
});

//on click event listener for the job description field - open larger window to read description
holder.desc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Toast.makeText(context, "Open Description", Toast.LENGTH_SHORT).show();

JobDescFragment firstFragment = new JobDescFragment();
Fragment frag = new Fragment();
frag = firstFragment.newJobDescFrag(j.getDescription());

((MainActivity) context).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, frag)
.addToBackStack("JobDesc").commit();
}
});


return view;
}

public class ViewHolder
{
TextView title;
TextView payrate;
TextView dateRange;
TextView workinghrs;
TextView location;
TextView companyname;
TextView desc;
TextView experience;
TextView equipment;
Button apply, dismiss, expand;
}
}

activity_main.xml:

<merge
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">

<com.lorentzos.flingswipe.SwipeFlingAdapterView
android:id="@+id/frame"
android:background="@color/laborswipe_lightgray"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context=".MainActivity"
android:layout_gravity="top" />

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</merge>

fragment 布局:

<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=".JobDescFragment">

<LinearLayout
android:id="@+id/outerDescriptionLayout"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_gravity="center_horizontal|top"
android:orientation="vertical"
android:background="@drawable/swipecard_shadow"
android:gravity="top"
android:layout_marginLeft="5dp">

<LinearLayout
android:id="@+id/DescriptionLayout"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_gravity="center_horizontal|top"
android:orientation="vertical"
android:weightSum="1"
android:gravity="top"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#00FF00"
android:clickable="true">

<TextView
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Detailed Description:"
android:textColor="#000000"
android:id="@+id/tv_title" />

<TextView
android:layout_width="200dp"
android:layout_height="200dp"
android:text="THIS IS THE FULL DESCRIPTION"
android:textColor="#000000"
android:id="@+id/tv_fullDescription" />
</LinearLayout>
</LinearLayout>

</FrameLayout>

日志:

08-07 11:20:47.799 13896-13896/com.lorentzos.swipecards.example I/System.out: DEBUG: job desc fragment loaded!
08-07 11:20:47.855 13896-13941/com.lorentzos.swipecards.example W/EGL_emulation: eglSurfaceAttrib not implemented
08-07 11:20:47.855 13896-13941/com.lorentzos.swipecards.example W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xaaa7f880, error=EGL_SUCCESS
08-07 11:20:48.002 13896-13941/com.lorentzos.swipecards.example V/RenderScript: 0xa1408000 Launching thread(s), CPUs 2
08-07 11:20:49.798 13896-13941/com.lorentzos.swipecards.example E/Surface: getSlotFromBufferLocked: unknown buffer: 0xae433ca0

当我使用底部栏时(不工作 - 没有打开 fragment 但显示了 toast):

enter image description here

当我不使用底栏时(workin-fragment 打开,背景为绿色):

enter image description here

最佳答案

尝试链接有问题和没有问题的图片(无底栏),并且由于您正在使用 merge 布局层次结构将根据您的 activity 的 viewgroup(linear,relative) constraints(我们不知道它们是什么样的)。

正如你所说,当没有没有底栏时,你的 fragment 显示完美虽然当底栏在那里时,问题统计,根据你的登录 fragment 表明你的 fragment 即使底部栏可见,也能完美加载意味着 fragment 存在但不可见,似乎您的 fragment 没有获得适当的空间来显示。

其他解决方案可以将底部栏添加到您的 fragment 而不是 Activity 以避免任何重叠,例如

mBottomBar.attach(findViewById(R.id.fragmentContainer), savedInstanceState);

关于java - 使用 BottomBar 可以防止 fragment 打开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38780747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com