Merge "Support customize layout in CollapsingToolbarBaseActivity" into sc-dev
This commit is contained in:
@@ -18,6 +18,7 @@ android_library {
|
|||||||
"androidx.core_core",
|
"androidx.core_core",
|
||||||
"com.google.android.material_material",
|
"com.google.android.material_material",
|
||||||
"SettingsLibSettingsTransition",
|
"SettingsLibSettingsTransition",
|
||||||
|
"SettingsLibUtils",
|
||||||
],
|
],
|
||||||
sdk_version: "system_current",
|
sdk_version: "system_current",
|
||||||
min_sdk_version: "29",
|
min_sdk_version: "29",
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ import androidx.annotation.Nullable;
|
|||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
|
import com.android.settingslib.utils.BuildCompatUtils;
|
||||||
|
|
||||||
import com.google.android.material.appbar.AppBarLayout;
|
import com.google.android.material.appbar.AppBarLayout;
|
||||||
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
||||||
import com.google.android.material.resources.TextAppearanceConfig;
|
import com.google.android.material.resources.TextAppearanceConfig;
|
||||||
@@ -44,10 +46,15 @@ public class CollapsingToolbarBaseActivity extends FragmentActivity {
|
|||||||
private CollapsingToolbarLayout mCollapsingToolbarLayout;
|
private CollapsingToolbarLayout mCollapsingToolbarLayout;
|
||||||
@Nullable
|
@Nullable
|
||||||
private AppBarLayout mAppBarLayout;
|
private AppBarLayout mAppBarLayout;
|
||||||
|
private int mCustomizeLayoutResId = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
if (mCustomizeLayoutResId > 0 && !BuildCompatUtils.isAtLeastS()) {
|
||||||
|
super.setContentView(mCustomizeLayoutResId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Force loading font synchronously for collapsing toolbar layout
|
// Force loading font synchronously for collapsing toolbar layout
|
||||||
TextAppearanceConfig.setShouldLoadFontSynchronously(true);
|
TextAppearanceConfig.setShouldLoadFontSynchronously(true);
|
||||||
super.setContentView(R.layout.collapsing_toolbar_base_layout);
|
super.setContentView(R.layout.collapsing_toolbar_base_layout);
|
||||||
@@ -81,12 +88,27 @@ public class CollapsingToolbarBaseActivity extends FragmentActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setContentView(View view) {
|
public void setContentView(View view) {
|
||||||
((ViewGroup) findViewById(R.id.content_frame)).addView(view);
|
final ViewGroup parent = findViewById(R.id.content_frame);
|
||||||
|
if (parent != null) {
|
||||||
|
parent.addView(view);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setContentView(View view, ViewGroup.LayoutParams params) {
|
public void setContentView(View view, ViewGroup.LayoutParams params) {
|
||||||
((ViewGroup) findViewById(R.id.content_frame)).addView(view, params);
|
final ViewGroup parent = findViewById(R.id.content_frame);
|
||||||
|
if (parent != null) {
|
||||||
|
parent.addView(view, params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method allows an activity to replace the default layout with a customize layout. Notice
|
||||||
|
* that it will no longer apply the features being provided by this class when this method
|
||||||
|
* gets called.
|
||||||
|
*/
|
||||||
|
protected void setCustomizeContentView(int layoutResId) {
|
||||||
|
mCustomizeLayoutResId = layoutResId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user