当前位置: 首页>>代码示例>>Java>>正文


Java Toolbar.getLayoutParams方法代码示例

本文整理汇总了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);
//                }
//            }
//        });
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:47,代码来源:StatusBarCompatKitKat.java

示例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));
}
 
开发者ID:GitLqr,项目名称:MaterialDesignDemo,代码行数:18,代码来源:FakeFabInteractiveActivity.java

示例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);
    }
}
 
开发者ID:Horrarndoo,项目名称:YiZhi,代码行数:14,代码来源:StatusBarUtils.java

示例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;
}
 
开发者ID:ls1110924,项目名称:ImmerseMode,代码行数:41,代码来源:FullInputActivity.java

示例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);
	}
}
 
开发者ID:SebastianRask,项目名称:Pocket-Plays-for-Twitch,代码行数:13,代码来源:Service.java

示例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);
    }

}
 
开发者ID:jthomperoo,项目名称:Forge,代码行数:46,代码来源:Forge.java

示例7: resetToolbarBehavior

import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
private void resetToolbarBehavior(Toolbar toolbar) {
    AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
    params.setScrollFlags(0);
}
 
开发者ID:mocircle,项目名称:devsuite-android,代码行数:5,代码来源:BaseSecondaryFragment.java

示例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));
    }
 
开发者ID:mainh,项目名称:MainCalendar,代码行数:74,代码来源:MainActivity.java


注:本文中的android.support.v7.widget.Toolbar.getLayoutParams方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。