有没有办法在设计支持 TabLayout 中动态更新选项卡的标题?我尝试在 Adapter 中添加一个方法,该方法更改保存选项卡标题的 ArrayList 的内容并通知适配器,但选项卡标题不会更改为新标题。
适配器:
public class TabAdapter extends FragmentPagerAdapter {
private final List<Fragment> fragments = new ArrayList<>();
private final List<String> fragmentTiles = new ArrayList<>();
public TabAdapter(FragmentManager fm) {
super(fm);
}
public void addFragment(Fragment fragment, String title) {
fragments.add(fragment);
fragmentTiles.add(title);
}
@Override
public Fragment getItem(int position) {
return fragments.get(position);
}
@Override
public int getCount() {
return fragments.size();
}
@Override
public CharSequence getPageTitle(int position) {
return fragmentTiles.get(position);
}
public void setFragmentTiles(int index, String title) {
fragmentTiles.set(index, title);
Log.e("ARRAY", …Run Code Online (Sandbox Code Playgroud) arraylist android-arrayadapter android-design-library androiddesignsupport android-tablayout
我在片段中有一个简单的折叠工具栏,它位于带有 tablayout 的 viewpager 中:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="192dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:expandedTitleMarginBottom="80dp"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:background="@color/red">
<android.support.v7.widget.Toolbar
android:id="@+id/anim_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
当我的片段第一次加载时一切正常,但是在选项卡之间交换后重新显示片段时,我无法再滚动到 NestedScrollView 的最底部。我的内容缺失部分与工具栏高度相同(更改工具栏高度会更改缺失部分高度)。
这是未滚动的视图:
滚动到底部时,有一个部分未显示,在本例中,还有另一个“Text 6”TextView 位于屏幕外且无法访问。
在某些选项卡上(我有 6 个),我永远无法访问缺少的部分,在其他选项卡上,它遵循以下模式:
任何帮助,将不胜感激。
android android-fragments android-design-library android-coordinatorlayout
我想在 ViewPager 中使用从一个 Fragment 到另一个 Fragment 的 SharedElement 转换为视图设置动画。
我在 ViewPager 中有 3 个片段,每个片段在 XML 文件中都有一个具有相同转换名称的 TextView。
现在,当 ViewPager 滑动另一个 Fragment 时,我想看到 SharedElement 的运行情况。
animation android shared-element-transition android-design-library
我正在尝试获取Snackbar's TextView。这是我正在使用的代码:
Snackbar snackbar = Snackbar.make(mRecyclerView, message, Snackbar.LENGTH_LONG);
View view = snackbar.getView();
TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
Run Code Online (Sandbox Code Playgroud)
运行上面的总是设置tv为空。我正在使用设计库版本23.0.0,在小吃店的布局资源中,我可以看到TextViewwith id snackbar_text。我错过了什么?
我正在设计库中使用 android 的新 BottomSheet。问题是我在片段中使用它,导致它出现在屏幕顶部而不是出现在底部。
这是我的活动 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="ir.aidinsoft.quicktaxi.MainActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/tlbr_acMain"
android:elevation="5dp"
android:background="@color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.design.widget.CoordinatorLayout
android:id="@+id/crdl_acMain"
android:layout_below="@+id/tlbr_acMain"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:id="@+id/nscv_acMain"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- This Layout Is Replacement Layout For Fragment -->
<RelativeLayout
android:id="@+id/frml_acMain"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的 xml 片段:
<android.support.design.widget.CoordinatorLayout 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"
tools:context="ir.aidinsoft.quicktaxi.MyFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<io.codetail.widget.RevealFrameLayout
android:id="@+id/rvfl_frTaxi"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible">
<fragment
android:id="@+id/frag_frTaxi_map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</io.codetail.widget.RevealFrameLayout>
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/facb_frTaxi_request"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!-- My Bottom …Run Code Online (Sandbox Code Playgroud) android android-fragments android-support-library android-design-library bottom-sheet
我的 TextView 标签看起来像这样
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableEnd="@drawable/search_pickup_address"
android:drawablePadding="@dimen/space"
android:scrollHorizontally="false"
android:ellipsize="end"
android:inputType="text"
android:maxLines="1"
android:minLines="1" />
Run Code Online (Sandbox Code Playgroud)
我已经设置了所有这些属性
android:scrollHorizontally="false"
android:ellipsize="end"
android:maxLines="1"
android:minLines="1"
Run Code Online (Sandbox Code Playgroud)由于 Single line true 方法已被弃用
android:singleLine="true"
Run Code Online (Sandbox Code Playgroud)当我使用这种方法时,点显示得很好。
String label;
if (string.length() >= 35) {
label= data.substring(0, 35)+ "...";
} else {
label= data;
}
textView.setText(label);
Run Code Online (Sandbox Code Playgroud)但是有没有像这样直接的方法
android:singleLine="true"
Run Code Online (Sandbox Code Playgroud)Textview我正在尝试为我的正常not添加色调AppCompatTextView。我可以在 xml 中添加 backgroundTint 来使用app:backgroundTint它。有没有办法以编程方式为Textview自己做同样的事情。(我的目标是Kitkat支持)
注:我还有更多Textview。所以改变所有这些都会很费力
setSupportButtonTintList仅适用于AppCompat控件。在KitkatsetBackgroundTintList中没有显示任何结果
java android android-appcompat android-layout android-design-library
我希望在底部工作表展开时将工具栏向上推出视图,并在折叠时将其拉回。我看到的所有示例都是合并到工具栏或捕捉到工具栏顶部的其他视图,但它们都没有隐藏工具栏。如何做到这一点?
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>
<FrameLayout
android:id="@+id/mainContentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/red"
/>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
>
<FrameLayout
android:id="@+id/topContentContainer"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/blue"
app:layout_scrollFlags="scroll|enterAlways|snap"
/>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/categoriesSelectionContainer"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@color/green"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="android.support.design.widget.AppBarLayout.ScrollingViewBehavior"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type …Run Code Online (Sandbox Code Playgroud) android android-layout android-design-library android-support-design
我想将 Persistent Bottom Sheet 制作为 Fragment 内的 Fragment,但找不到任何方法来实现它。无处不在的持久性底部表被添加为活动/片段内的布局,但是否可以将持久性底部表作为片段,以便我可以在其他地方重用该视图?
android android-fragments android-design-library bottom-sheet
我BottomNavigationView用于底部标签。
1) Tab 1 - 从服务器获取数据并显示到RecyclerView
2) Tab 2 - 从服务器获取 URL 并加载Webview
3) Tab 3 - 从服务器获取数据并显示到RecyclerView
4) Tab 4 - 设置屏幕使用PreferenceFragmentCompat
为了在用户切换选项卡时保存这些片段的状态,我使用了此博客中的以下代码
保存Fragment.SavedState到SparseArray<Fragment.SavedState>
Fragment.State currentFragmentState = getSupportFragmentManager().saveFragmentInstanceState(currentFragment)
Run Code Online (Sandbox Code Playgroud)
当用户导航回之前的选项卡时再次恢复状态
fragment.setInitialSavedState(savedState)
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.container_fragment, fragment, tag)
.commit();
Run Code Online (Sandbox Code Playgroud)
我看到的是只有 Tab 4(设置屏幕 PreferenceFragmentCompat)保持状态 - 如果我向下滚动到第 10 个项目并在导航到其他片段后再次返回设置屏幕,我会在顶部看到第 10 个位置。
但是,前三个选项卡会再次调用 Web 服务,并且所有内容都会重新加载。另外,我可以看到前三个选项卡Bundle savedInstanceState的onCreateView方法参数也不为空。
我的问题是
1) PreferenceFragmentCompat(4th tab ) 如何自动恢复状态?
2)如何在前三个选项卡中使用非空Bundle savedInstanceState(onCreateView方法的参数)并像第四个选项卡一样恢复状态? …
android android-fragments android-design-library bottomnavigationview