本文整理汇总了Java中android.support.v7.widget.Toolbar.getLayoutParams方法的典型用法代码示例。如果您正苦于以下问题:Java Toolbar.getLayoutParams方法的具体用法?Java Toolbar.getLayoutParams怎么用?Java Toolbar.getLayoutParams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.Toolbar
的用法示例。
在下文中一共展示了Toolbar.getLayoutParams方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setStatusBarColorForCollapsingToolbar
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
/**
* compat for CollapsingToolbarLayout
* 1. set Window Flag : WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
* 2. set FitsSystemWindows for views.
* 3. removeFakeStatusBarViewIfExist
* 4. removeMarginTopOfContentChild
* 5. add OnOffsetChangedListener to change statusBarView's alpha
*/
public static void setStatusBarColorForCollapsingToolbar(Activity activity, final AppBarLayout appBarLayout, final CollapsingToolbarLayout collapsingToolbarLayout,
Toolbar toolbar, int statusColor) {
Window window = activity.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
View mContentChild = mContentView.getChildAt(0);
mContentChild.setFitsSystemWindows(false);
((View) appBarLayout.getParent()).setFitsSystemWindows(false);
appBarLayout.setFitsSystemWindows(false);
collapsingToolbarLayout.setFitsSystemWindows(false);
collapsingToolbarLayout.getChildAt(0).setFitsSystemWindows(false);
toolbar.setFitsSystemWindows(true);
if (toolbar.getTag() == null) {
CollapsingToolbarLayout.LayoutParams lp = (CollapsingToolbarLayout.LayoutParams) toolbar.getLayoutParams();
lp.height += getStatusBarHeight(activity);
toolbar.setLayoutParams(lp);
toolbar.setTag(true);
}
int statusBarHeight = getStatusBarHeight(activity);
removeFakeStatusBarViewIfExist(activity);
removeMarginTopOfContentChild(mContentChild, statusBarHeight);
// final View statusView = addFakeStatusBarView(activity, statusColor, statusBarHeight);
// appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
// @Override
// public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
// if (Math.abs(verticalOffset) > appBarLayout.getHeight() - collapsingToolbarLayout.getStatusBarScrim().getIntrinsicHeight()) {
// if (statusView.getAlpha() == 0) {
// statusView.animate().alpha(1f).setDuration(collapsingToolbarLayout.getScrollBarFadeDuration()).start();
// }
// } else {
// statusView.setAlpha(0);
// }
// }
// });
}
示例2: onCreate
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fake_fab_interactive);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
mRv = (RecyclerView) findViewById(R.id.rv);
mFab = (ImageButton) findViewById(R.id.fab);
mToolbarBottomMargin = ((ViewGroup.MarginLayoutParams) mToolbar.getLayoutParams()).bottomMargin;
mFabBottomMargin = ((ViewGroup.MarginLayoutParams) mFab.getLayoutParams()).bottomMargin;
mRv.setLayoutManager(new LinearLayoutManager(this));
mRv.setAdapter(new MyAdapter(mData));
mRv.addOnScrollListener(new FakeFabScrollListener(this));
}
示例3: fixToolbar
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
/**
* 修正 Toolbar 的位置
* 在 Android 4.4 版本下无法显示内容在 StatusBar 下,所以无需修正 Toolbar 的位置
*
* @param toolbar
*/
public static void fixToolbar(Toolbar toolbar, Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
int statusHeight = getStatusBarHeight(activity);
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
layoutParams.setMargins(0, statusHeight, 0, 0);
}
}
示例4: onCreate
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_full_input);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
toolbar.setBackgroundColor(Color.TRANSPARENT);
ImmerseConfiguration.Builder builder = new ImmerseConfiguration.Builder();
Bundle bundle = getIntent().getExtras();
String paras = bundle.getString("Mode");
if ("TLSB_NNB_FC_AR".equals(paras)) {
builder.setStatusBarModeInKK(ImmerseConfiguration.TRANSLUCENT).setNavigationBarModeInKK(ImmerseConfiguration.NORMAL)
.setFullScreenInKK(true).setAdjustResizeInKK(true);
builder.setStatusBarModeInL(ImmerseConfiguration.TRANSLUCENT).setNavigationBarModeInL(ImmerseConfiguration.NORMAL)
.setFullScreenInL(true).setAdjustResizeInL(true);
} else if ("TPSB_NNB_FC_AR".equals(paras)) {
builder.setStatusBarModeInKK(ImmerseConfiguration.TRANSLUCENT).setNavigationBarModeInKK(ImmerseConfiguration.NORMAL)
.setFullScreenInKK(true).setAdjustResizeInKK(true);
builder.setStatusBarModeInL(ImmerseConfiguration.TRANSPARENT).setNavigationBarModeInL(ImmerseConfiguration.NORMAL)
.setFullScreenInL(true).setAdjustResizeInL(true);
} else {
// 补偿逻辑
builder.setStatusBarModeInKK(ImmerseConfiguration.NORMAL).setNavigationBarModeInKK(ImmerseConfiguration.NORMAL)
.setFullScreenInKK(false);
builder.setStatusBarModeInL(ImmerseConfiguration.NORMAL).setNavigationBarModeInL(ImmerseConfiguration.NORMAL)
.setFullScreenInL(false);
}
ImmerseHelper immerseHelper = new ImmerseHelper(this, builder.build());
immerseHelper.setStatusColor(Color.TRANSPARENT);
immerseHelper.setNavigationColorRes(R.color.colorAccent);
Rect insetsRect = immerseHelper.getInsetsPadding();
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) toolbar.getLayoutParams();
params.topMargin = insetsRect.top;
}
示例5: isTranslucentActionbar
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
public static void isTranslucentActionbar(String LOG_TAG, Context context, Toolbar toolbar, Activity activity) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
Log.d(LOG_TAG, "Settings translucent status bar");
double statusBarHeight = Math.ceil(25 * context.getResources().getDisplayMetrics().density);
Window w = activity.getWindow(); // in Activity's onCreate() for instance
//w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
toolbar.getLayoutParams().height = (int) (context.getResources().getDimension((R.dimen.main_toolbar_height)) + statusBarHeight);
}
}
示例6: onCreate
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_forge);
// Open with keyboard hidden
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
// Set up toolbar
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Set up fragment pager adapter
forgePagerAdapter = new ForgePagerAdapter(getSupportFragmentManager(), getApplicationContext());
// Clear all scroll flags
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
params.setScrollFlags(0);
// Set up viewpager
viewPager = findViewById(R.id.container);
viewPager.setAdapter(forgePagerAdapter);
// Set up tab layout
TabLayout tabLayout = findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
// Set up notification channel
Notifications.setUpChannels(this);
// Get shared preferences
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
// Get activity starting intent
Intent intent = getIntent();
if (intent.hasExtra(Notifications.NOTIFICATION_NAVIGATION)) {
// If the activity was opened from a notification click
// Set the current fragment viewed to the one requested
viewPager.setCurrentItem(intent.getIntExtra(Notifications.NOTIFICATION_NAVIGATION, GENERATE_TAB));
}
// If the user preferences have not been set yet, set them to defaults
if (!sharedPref.getBoolean(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, false)) {
PreferenceManager.setDefaultValues(getApplicationContext(), R.xml.pref_general, true);
PreferenceManager.setDefaultValues(getApplicationContext(), R.xml.pref_password, true);
PreferenceManager.setDefaultValues(getApplicationContext(), R.xml.pref_date_of_birth, true);
}
if (sharedPref.getBoolean(getString(R.string.pref_helper_key), false)) {
Notifications.displayHelperNotification(this);
} else {
Notifications.removeHelperNotification(this);
}
}
示例7: resetToolbarBehavior
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
private void resetToolbarBehavior(Toolbar toolbar) {
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
params.setScrollFlags(0);
}
示例8: onCreate
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 设置透明状态栏
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
ViewGroup contentFrameLayout = (ViewGroup) findViewById(Window.ID_ANDROID_CONTENT);
if (contentFrameLayout != null) {
View parentView = contentFrameLayout.getChildAt(0);
if (parentView != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
parentView.setFitsSystemWindows(true);
}
}
setContentView(R.layout.activity_main);
// 获取屏幕方向
mOrientation = getResources().getConfiguration().orientation;
// 载入闹钟类型
AppConstants.AlarmTypeNames = getResources().getStringArray(R.array.alarm_type_names);
// 更新日期
DateUtil.updateCurrent();
// 载入必须服务
AppConstants.loadGlobalService(this);
// 开启后台服务
// if (!Helper.isServiceRunning(this, CalendarService.class.getName())) {
// AppConstants.DLog("Enter in service...");
startService(new Intent(this, CalendarService.class));
// }
// 初始化闹钟记录
AlarmRecordMng.initAlarmRecords();
ShiftsWorkRecordMng.loadDisplayWork();
mToolbar = (Toolbar) findViewById(R.id.toolbar);
if (mToolbar != null) {
int statusHeight = Helper.getStatusHeight(this);
mToolbar.getLayoutParams().height += statusHeight;
mToolbar.setPadding(mToolbar.getPaddingLeft(), statusHeight, mToolbar.getPaddingRight(), mToolbar.getPaddingBottom());
mToolbar.setBackgroundColor(ThemeStyle.Primary);
}
mSolarTitle = (TextView) findViewById(R.id.solarTitle);
if (mSolarTitle != null) {
mSolarTitle.setOnClickListener(this);
}
// 设置右上角的填充菜单
mToolbar.inflateMenu(R.menu.menu_main);
mToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
return onOptionsItemSelected(item);
}
});
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
if (fab != null) {
fab.setOnClickListener(this);
}
// 获取页面资源
setViewPager();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_DATE_CHANGED);
mDateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context ctx, Intent intent) {
onReceiveDate(intent);
}
};
registerReceiver(mDateReceiver, intentFilter);
WeatherIconUtil.initWeatherNames(getResources().getStringArray(R.array.weather_names));
}