如何以编程方式为此活动添加单个按钮? (电报api)

时间:2017-12-10 14:52:34

标签: java android telegram

实际上我正在使用这部分代码但屏幕上没有显示

// add single button for find near me
Button myButton = new Button(this);
myButton.setText("Press me");
myButton.setBackgroundColor(Color.YELLOW);

RelativeLayout.LayoutParams buttonParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, elativeLayout.LayoutParams.WRAP_CONTENT);

buttonParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
buttonParams.addRule(RelativeLayout.CENTER_VERTICAL);
launchLayout.addView(myButton,buttonParams);
setContentView(launchLayout);

这是活动代码

public class LaunchActivity extends Activity implements ActionBarLayout.ActionBarLayoutDelegate, NotificationCenter.NotificationCenterDelegate, DialogsActivity.DialogsActivityDelegate {

private boolean finished;
private String videoPath;
private String sendingText;
private ArrayList<Uri> photoPathsArray;
private ArrayList<String> documentsPathsArray;
private ArrayList<Uri> documentsUrisArray;
private String documentsMimeType;
private ArrayList<String> documentsOriginalPathsArray;
private ArrayList<TLRPC.User> contactsToSend;
private int currentConnectionState;
private static ArrayList<BaseFragment> mainFragmentsStack = new ArrayList<>();
private static ArrayList<BaseFragment> layerFragmentsStack = new ArrayList<>();
private static ArrayList<BaseFragment> rightFragmentsStack = new ArrayList<>();
private ViewTreeObserver.OnGlobalLayoutListener onGlobalLayoutListener;

private ActionBarLayout actionBarLayout;
private ActionBarLayout layersActionBarLayout;
private ActionBarLayout rightActionBarLayout;
private FrameLayout shadowTablet;
private FrameLayout shadowTabletSide;
private View backgroundTablet;
protected DrawerLayoutContainer drawerLayoutContainer;
private DrawerLayoutAdapter drawerLayoutAdapter;
private PasscodeView passcodeView;
private AlertDialog visibleDialog;
private RecyclerListView sideMenu;

private AlertDialog localeDialog;
private boolean loadingLocaleDialog;
private HashMap<String, String> systemLocaleStrings;
private HashMap<String, String> englishLocaleStrings;

private Intent passcodeSaveIntent;
private boolean passcodeSaveIntentIsNew;
private boolean passcodeSaveIntentIsRestore;

private boolean tabletFullSize;

private Runnable lockRunnable;


@Override
protected void onCreate(Bundle savedInstanceState) {
    ApplicationLoader.postInitApplication();
    NativeCrashManager.handleDumpFiles(this);
    AndroidUtilities.checkDisplaySize(this, getResources().getConfiguration());


    Log.i(this.getClass().getName(), "onCreate: ");


    if (!UserConfig.isClientActivated()) {
        Intent intent = getIntent();
        if (intent != null && intent.getAction() != null && (Intent.ACTION_SEND.equals(intent.getAction()) || intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE))) {
            super.onCreate(savedInstanceState);
            finish();
            return;
        }
        SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
        long crashed_time = preferences.getLong("intro_crashed_time", 0);
        boolean fromIntro = intent.getBooleanExtra("fromIntro", false);
        if (fromIntro) {
            preferences.edit().putLong("intro_crashed_time", 0).commit();
        }
        if (Math.abs(crashed_time - System.currentTimeMillis()) >= 60 * 2 * 1000 && intent != null && !fromIntro) {
            preferences = ApplicationLoader.applicationContext.getSharedPreferences("logininfo2", MODE_PRIVATE);
            Map<String, ?> state = preferences.getAll();
            if (state.isEmpty()) {
                Intent intent2 = new Intent(this, IntroActivity.class);
                intent2.setData(intent.getData());
                startActivity(intent2);
                super.onCreate(savedInstanceState);
                finish();
                return;
            }
        }
    }

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setTheme(R.style.Theme_TMessages);
    getWindow().setBackgroundDrawableResource(R.drawable.transparent);
    if (UserConfig.passcodeHash.length() > 0 && !UserConfig.allowScreenCapture) {
        try {
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
        } catch (Exception e) {
            FileLog.e(e);
        }
    }

    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= 24) {
        AndroidUtilities.isInMultiwindow = isInMultiWindowMode();
    }
    Theme.createChatResources(this, false);
    if (UserConfig.passcodeHash.length() != 0 && UserConfig.appLocked) {
        UserConfig.lastPauseTime = ConnectionsManager.getInstance().getCurrentTime();
    }

    int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        AndroidUtilities.statusBarHeight = getResources().getDimensionPixelSize(resourceId);
    }


    actionBarLayout = new ActionBarLayout(this);


    drawerLayoutContainer = new DrawerLayoutContainer(this);


    setContentView(drawerLayoutContainer, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

    if (AndroidUtilities.isTablet()) {
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

        RelativeLayout launchLayout = new RelativeLayout(this) {

            private boolean inLayout;

            @Override
            public void requestLayout() {
                if (inLayout) {
                    return;
                }
                super.requestLayout();

            }

            @Override
            protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                inLayout = true;
                int width = MeasureSpec.getSize(widthMeasureSpec);
                int height = MeasureSpec.getSize(heightMeasureSpec);
                setMeasuredDimension(width, height);

                if (!AndroidUtilities.isInMultiwindow && (!AndroidUtilities.isSmallTablet() || getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)) {
                    tabletFullSize = false;
                    int leftWidth = width / 100 * 35;
                    if (leftWidth < AndroidUtilities.dp(320)) {
                        leftWidth = AndroidUtilities.dp(320);
                    }
                    actionBarLayout.measure(MeasureSpec.makeMeasureSpec(leftWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
                    shadowTabletSide.measure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
                    rightActionBarLayout.measure(MeasureSpec.makeMeasureSpec(width - leftWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
                } else {
                    tabletFullSize = true;
                    actionBarLayout.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
                }
                backgroundTablet.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
                shadowTablet.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
                layersActionBarLayout.measure(MeasureSpec.makeMeasureSpec(Math.min(AndroidUtilities.dp(530), width), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(Math.min(AndroidUtilities.dp(528), height), MeasureSpec.EXACTLY));

                inLayout = false;
            }

            @Override
            protected void onLayout(boolean changed, int l, int t, int r, int b) {
                int width = r - l;
                int height = b - t;

                if (!AndroidUtilities.isInMultiwindow && (!AndroidUtilities.isSmallTablet() || getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)) {
                    int leftWidth = width / 100 * 35;
                    if (leftWidth < AndroidUtilities.dp(320)) {
                        leftWidth = AndroidUtilities.dp(320);
                    }
                    shadowTabletSide.layout(leftWidth, 0, leftWidth + shadowTabletSide.getMeasuredWidth(), shadowTabletSide.getMeasuredHeight());
                    actionBarLayout.layout(0, 0, actionBarLayout.getMeasuredWidth(), actionBarLayout.getMeasuredHeight());
                    rightActionBarLayout.layout(leftWidth, 0, leftWidth + rightActionBarLayout.getMeasuredWidth(), rightActionBarLayout.getMeasuredHeight());
                } else {
                    actionBarLayout.layout(0, 0, actionBarLayout.getMeasuredWidth(), actionBarLayout.getMeasuredHeight());
                }
                int x = (width - layersActionBarLayout.getMeasuredWidth()) / 2;
                int y = (height - layersActionBarLayout.getMeasuredHeight()) / 2;
                layersActionBarLayout.layout(x, y, x + layersActionBarLayout.getMeasuredWidth(), y + layersActionBarLayout.getMeasuredHeight());
                backgroundTablet.layout(0, 0, backgroundTablet.getMeasuredWidth(), backgroundTablet.getMeasuredHeight());
                shadowTablet.layout(0, 0, shadowTablet.getMeasuredWidth(), shadowTablet.getMeasuredHeight());
            }
        };


        drawerLayoutContainer.addView(launchLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

        backgroundTablet = new View(this);
        //BitmapDrawable drawable = (BitmapDrawable) getResources().getDrawable(R.drawable.catstile);
        //drawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
        backgroundTablet.setBackgroundResource(R.drawable.catstile);
        launchLayout.addView(backgroundTablet, LayoutHelper.createRelative(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

        launchLayout.addView(actionBarLayout);

        rightActionBarLayout = new ActionBarLayout(this);
        rightActionBarLayout.init(rightFragmentsStack);
        rightActionBarLayout.setDelegate(this);
        launchLayout.addView(rightActionBarLayout);

        shadowTabletSide = new FrameLayout(this);
        shadowTabletSide.setBackgroundColor(0x40295274);


        launchLayout.addView(shadowTabletSide);

        shadowTablet = new FrameLayout(this);
        shadowTablet.setVisibility(layerFragmentsStack.isEmpty() ? View.GONE : View.VISIBLE);
        shadowTablet.setBackgroundColor(0x7f000000);
        launchLayout.addView(shadowTablet);
        shadowTablet.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (!actionBarLayout.fragmentsStack.isEmpty() && event.getAction() == MotionEvent.ACTION_UP) {
                    float x = event.getX();
                    float y = event.getY();
                    int location[] = new int[2];
                    layersActionBarLayout.getLocationOnScreen(location);
                    int viewX = location[0];
                    int viewY = location[1];

                    if (layersActionBarLayout.checkTransitionAnimation() || x > viewX && x < viewX + layersActionBarLayout.getWidth() && y > viewY && y < viewY + layersActionBarLayout.getHeight()) {
                        return false;
                    } else {
                        if (!layersActionBarLayout.fragmentsStack.isEmpty()) {
                            for (int a = 0; a < layersActionBarLayout.fragmentsStack.size() - 1; a++) {
                                layersActionBarLayout.removeFragmentFromStack(layersActionBarLayout.fragmentsStack.get(0));
                                a--;
                            }
                            layersActionBarLayout.closeLastFragment(true);
                        }
                        return true;
                    }
                }
                return false;
            }
        });

        shadowTablet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });


        layersActionBarLayout = new ActionBarLayout(this);
        layersActionBarLayout.setRemoveActionBarExtraHeight(true);
        layersActionBarLayout.setBackgroundView(shadowTablet);
        layersActionBarLayout.setUseAlphaAnimations(true);
        layersActionBarLayout.setBackgroundResource(R.drawable.boxshadow);
        layersActionBarLayout.init(layerFragmentsStack);
        layersActionBarLayout.setDelegate(this);
        layersActionBarLayout.setDrawerLayoutContainer(drawerLayoutContainer);
        layersActionBarLayout.setVisibility(layerFragmentsStack.isEmpty() ? View.GONE : View.VISIBLE);
        launchLayout.addView(layersActionBarLayout);

        // add single button for find near me
        Button myButton = new Button(this);
        myButton.setText("Press me");
        myButton.setBackgroundColor(Color.YELLOW);

        RelativeLayout.LayoutParams buttonParams =
                new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.WRAP_CONTENT,
                        RelativeLayout.LayoutParams.WRAP_CONTENT);

        buttonParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
        buttonParams.addRule(RelativeLayout.CENTER_VERTICAL);
        launchLayout.addView(myButton,buttonParams);
        setContentView(launchLayout);
    } else {
        drawerLayoutContainer.addView(actionBarLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    }


    sideMenu = new RecyclerListView(this);
    sideMenu.setBackgroundColor(Theme.getColor(Theme.key_chats_menuBackground));
    sideMenu.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    sideMenu.setAdapter(drawerLayoutAdapter = new DrawerLayoutAdapter(this));
    drawerLayoutContainer.setDrawerLayout(sideMenu);
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) sideMenu.getLayoutParams();
    Point screenSize = AndroidUtilities.getRealScreenSize();
    layoutParams.width = AndroidUtilities.isTablet() ? AndroidUtilities.dp(320) : Math.min(AndroidUtilities.dp(320), Math.min(screenSize.x, screenSize.y) - AndroidUtilities.dp(56));
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    sideMenu.setLayoutParams(layoutParams);
    sideMenu.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
        @Override
        public void onItemClick(final View view, int position) {
            int id = drawerLayoutAdapter.getId(position);
            if (position == 0) {
                Bundle args = new Bundle();
                args.putInt("user_id", UserConfig.getClientUserId());
                presentFragment(new ChatActivity(args));
                drawerLayoutContainer.closeDrawer(false);
            } else if (id == 2) {
                if (!MessagesController.isFeatureEnabled("chat_create", actionBarLayout.fragmentsStack.get(actionBarLayout.fragmentsStack.size() - 1))) {
                    return;
                }
                presentFragment(new GroupCreateActivity());
                drawerLayoutContainer.closeDrawer(false);
            } else if (id == 3) {
                Bundle args = new Bundle();
                args.putBoolean("onlyUsers", true);
                args.putBoolean("destroyAfterSelect", true);
                args.putBoolean("createSecretChat", true);
                args.putBoolean("allowBots", false);
                presentFragment(new ContactsActivity(args));
                drawerLayoutContainer.closeDrawer(false);
            } else if (id == 4) {
                if (!MessagesController.isFeatureEnabled("broadcast_create", actionBarLayout.fragmentsStack.get(actionBarLayout.fragmentsStack.size() - 1))) {
                    return;
                }
                SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                if (!BuildVars.DEBUG_VERSION && preferences.getBoolean("channel_intro", false)) {
                    Bundle args = new Bundle();
                    args.putInt("step", 0);
                    presentFragment(new ChannelCreateActivity(args));
                } else {
                    presentFragment(new ChannelIntroActivity());
                    preferences.edit().putBoolean("channel_intro", true).commit();
                }
                drawerLayoutContainer.closeDrawer(false);
            } else if (id == 6) {
                presentFragment(new ContactsActivity(null));
                drawerLayoutContainer.closeDrawer(false);
            } else if (id == 7) {
                if (BuildVars.DEBUG_PRIVATE_VERSION) {
                    /*AlertDialog.Builder builder = new AlertDialog.Builder(LaunchActivity.this);
                    builder.setTopImage(R.drawable.permissions_contacts, 0xff35a8e0);
                    builder.setMessage(AndroidUtilities.replaceTags(LocaleController.getString("ContactsPermissionAlert", R.string.ContactsPermissionAlert)));
                    builder.setPositiveButton(LocaleController.getString("ContactsPermissionAlertContinue", R.string.ContactsPermissionAlertContinue), new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {

                        }
                    });
                    builder.setNegativeButton(LocaleController.getString("ContactsPermissionAlertNotNow", R.string.ContactsPermissionAlertNotNow), null);
                    showAlertDialog(builder);*/
                    showLanguageAlert(true);
                } else {
                    try {
                        Intent intent = new Intent(Intent.ACTION_SEND);
                        intent.setType("text/plain");
                        intent.putExtra(Intent.EXTRA_TEXT, ContactsController.getInstance().getInviteText());
                        startActivityForResult(Intent.createChooser(intent, LocaleController.getString("InviteFriends", R.string.InviteFriends)), 500);
                    } catch (Exception e) {
                        FileLog.e(e);
                    }
                    drawerLayoutContainer.closeDrawer(false);
                }
            } else if (id == 8) {
                presentFragment(new SettingsActivity());
                drawerLayoutContainer.closeDrawer(false);
            } else if (id == 9) {
                Browser.openUrl(LaunchActivity.this, LocaleController.getString("TelegramFaqUrl", R.string.TelegramFaqUrl));
                drawerLayoutContainer.closeDrawer(false);
            } else if (id == 10) {
                presentFragment(new CallLogActivity());
                drawerLayoutContainer.closeDrawer(false);
            }
        }
    });

    drawerLayoutContainer.setParentActionBarLayout(actionBarLayout);
    actionBarLayout.setDrawerLayoutContainer(drawerLayoutContainer);
    actionBarLayout.init(mainFragmentsStack);
    actionBarLayout.setDelegate(this);

    Theme.loadWallpaper();

    passcodeView = new PasscodeView(this);
    drawerLayoutContainer.addView(passcodeView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeOtherAppActivities, this);
    currentConnectionState = ConnectionsManager.getInstance().getConnectionState();

    NotificationCenter.getInstance().addObserver(this, NotificationCenter.appDidLogout);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.mainUserInfoChanged);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeOtherAppActivities);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.didUpdatedConnectionState);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.needShowAlert);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.wasUnableToFindCurrentLocation);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.didSetNewWallpapper);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.didSetPasscode);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.reloadInterface);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.suggestedLangpack);

    if (actionBarLayout.fragmentsStack.isEmpty()) {
        if (!UserConfig.isClientActivated()) {
            actionBarLayout.addFragmentToStack(new LoginActivity());
            drawerLayoutContainer.setAllowOpenDrawer(false, false);
        } else {
            DialogsActivity dialogsActivity = new DialogsActivity(null);
            dialogsActivity.setSideMenu(sideMenu);
            actionBarLayout.addFragmentToStack(dialogsActivity);
            drawerLayoutContainer.setAllowOpenDrawer(true, false);
        }

        try {
            if (savedInstanceState != null) {
                String fragmentName = savedInstanceState.getString("fragment");
                if (fragmentName != null) {
                    Bundle args = savedInstanceState.getBundle("args");
                    switch (fragmentName) {
                        case "chat":
                            if (args != null) {
                                ChatActivity chat = new ChatActivity(args);
                                if (actionBarLayout.addFragmentToStack(chat)) {
                                    chat.restoreSelfArgs(savedInstanceState);
                                }
                            }
                            break;
                        case "settings": {
                            SettingsActivity settings = new SettingsActivity();
                            actionBarLayout.addFragmentToStack(settings);
                            settings.restoreSelfArgs(savedInstanceState);
                            break;
                        }
                        case "group":
                            if (args != null) {
                                GroupCreateFinalActivity group = new GroupCreateFinalActivity(args);
                                if (actionBarLayout.addFragmentToStack(group)) {
                                    group.restoreSelfArgs(savedInstanceState);
                                }
                            }
                            break;
                        case "channel":
                            if (args != null) {
                                ChannelCreateActivity channel = new ChannelCreateActivity(args);
                                if (actionBarLayout.addFragmentToStack(channel)) {
                                    channel.restoreSelfArgs(savedInstanceState);
                                }
                            }
                            break;
                        case "edit":
                            if (args != null) {
                                ChannelEditActivity channel = new ChannelEditActivity(args);
                                if (actionBarLayout.addFragmentToStack(channel)) {
                                    channel.restoreSelfArgs(savedInstanceState);
                                }
                            }
                            break;
                        case "chat_profile":
                            if (args != null) {
                                ProfileActivity profile = new ProfileActivity(args);
                                if (actionBarLayout.addFragmentToStack(profile)) {
                                    profile.restoreSelfArgs(savedInstanceState);
                                }
                            }
                            break;
                        case "wallpapers": {
                            WallpapersActivity settings = new WallpapersActivity();
                            actionBarLayout.addFragmentToStack(settings);
                            settings.restoreSelfArgs(savedInstanceState);
                            break;
                        }
                    }
                }
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    } else {
        BaseFragment fragment = actionBarLayout.fragmentsStack.get(0);
        if (fragment instanceof DialogsActivity) {
            ((DialogsActivity) fragment).setSideMenu(sideMenu);
        }
        boolean allowOpen = true;
        if (AndroidUtilities.isTablet()) {
            allowOpen = actionBarLayout.fragmentsStack.size() <= 1 && layersActionBarLayout.fragmentsStack.isEmpty();
            if (layersActionBarLayout.fragmentsStack.size() == 1 && layersActionBarLayout.fragmentsStack.get(0) instanceof LoginActivity) {
                allowOpen = false;
            }
        }
        if (actionBarLayout.fragmentsStack.size() == 1 && actionBarLayout.fragmentsStack.get(0) instanceof LoginActivity) {
            allowOpen = false;
        }
        drawerLayoutContainer.setAllowOpenDrawer(allowOpen, false);
    }
    checkLayout();


    handleIntent(getIntent(), false, savedInstanceState != null, false);

    try {
        String os1 = Build.DISPLAY;
        String os2 = Build.USER;
        if (os1 != null) {
            os1 = os1.toLowerCase();
        } else {
            os1 = "";
        }
        if (os2 != null) {
            os2 = os1.toLowerCase();
        } else {
            os2 = "";
        }
        if (os1.contains("flyme") || os2.contains("flyme")) {
            AndroidUtilities.incorrectDisplaySizeFix = true;
            final View view = getWindow().getDecorView().getRootView();
            view.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    int height = view.getMeasuredHeight();
                    if (Build.VERSION.SDK_INT >= 21) {
                        height -= AndroidUtilities.statusBarHeight;
                    }
                    if (height > AndroidUtilities.dp(100) && height < AndroidUtilities.displaySize.y && height + AndroidUtilities.dp(100) > AndroidUtilities.displaySize.y) {
                        AndroidUtilities.displaySize.y = height;
                        FileLog.e("fix display size y to " + AndroidUtilities.displaySize.y);
                    }
                }
            });
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
    MediaController.getInstance().setBaseActivity(this, true);
} 

0 个答案:

没有答案