简体   繁体   English

为什么设计(activity_main.xml)和实际应用看起来不同?

[英]Why Design(activity_main.xml) and actual app look different?

i am new in Android development in java我是 java 中 Android 开发的新手

my activity_main.xml file is look like this我的 activity_main.xml 文件看起来像这样activity_main.xml 设计

But when i run this application in my pixel 3 phone than it's look's like但是当我在我的像素 3 手机上运行这个应用程序时,它看起来像像素 3 手机

why this design are different?为什么这个设计不同?

check your style file.检查您的样式文件。 By default is with Dialog.默认情况下是对话框。 u can change it with No Dialog你可以用无对话框来改变它

Sorry i mean the line对不起,我的意思是线

  <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

u can change the theme with no actionbar您可以在没有操作栏的情况下更改主题

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

there are many variants有很多变种

As seen in background, you ignore missing constraints.如背景中所见,您忽略了缺失的约束。 When working with ConstraintLayout you must provide at least one horizontal and one vertical constraint, otherwise views could jump, and I believe IDE gave u that error.使用 ConstraintLayout 时,您必须提供至少一个水平约束和一个垂直约束,否则视图可能会跳转,我相信 IDE 给了你这个错误。

if you want to have a full screen theme like Design(activity_main.xml):如果你想要像 Design(activity_main.xml) 这样的全屏主题:

solution 1 : go into the manifest and use a full screen theme.解决方案1 :go 进入清单并使用全屏主题。

 <activity
   . 
   .
   android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

solution 2 :解决方案 2

Just add the following attribute to your current theme:只需将以下属性添加到您当前的主题:

<item name="android:windowFullscreen">true</item>

for example:例如:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/orange</item>
<item name="colorPrimaryDark">@android:color/holo_orange_dark</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>

solution 3 :解决方案 3

 public class MainActivity extends AppCompatActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.main);
    }

} }

and for manage your buttons, read Dorian's answer to Design and actual app look same.并且要管理您的按钮,请阅读Dorian 对设计的回答,实际应用看起来相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM