**
@一篇个人总结的博客
**
一篇个人总结错误的博客
这是第一次使用 Markdown编辑器 。并正式发表博客。
开始的程序
最近学习了如何画UI界面,并做了一个很简单的成绩分析程序,这是我第一次接触java和android开发,好在有学长和舍友的帮助,才没有过于的困难,但也是遇到了很多问题
问题及解决
如何插入一个图片?
1.首先,需要找一个自己喜欢的图片并下载到桌面上,如果使用icon图标
(https://www.iconfont.cn/),直接点击图标进行png下载,或先加入购物车
再下载都可以。
2.然后复制桌面上的图片,并在android中点击drawable进行粘贴(直接粘贴就可以
了),之后会弹出一个框,是不同的文件夹,在不同的drawable,mipmap文件夹为设
备兼容性和不同的Android版本提供不同的屏幕密度。
3.然后起一个英文名字方便之后用"变量=@drawable/名字",一般是在ImageView中
使用。
4.如果想要调整图片位置可采用paddingLeft,paddingTop,padding等。
如何跳转?
1.设置button(注意:如果说TextView和EditText经常需要用到id,那Button几乎
必定要用到id,形如android:id="@+id/button")
2.然后在button对应的activity中定义button并获取id((Button buttton =
findViewById(R.id.button);
buttton.setOnClickListener(new View.OnClickListener() {})
设置点击事件)
3.设置跳转语句: Button buttton = findViewById(R.id.button);
buttton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(first.this, MainActivity.class);
startActivity(intent);
finish();
}
});
4.如需要传值,请看下一部分。
传值
1.参考代码(String str1 = editText.getText().toString();//接受数据
intent.putExtra("key1", editText.getText().toString());//传值
String s1 = getIntent().getStringExtra("key1");//在另一个activity中接受数据
textView1.setText((String)s1);//传值 )
2.如果要对数据进行计算,需要先变成可以计算的int或double,但如果还需要
传值,需要把这些数据变回string型(具体如何变化请具体搜索)。
关于AndroidManifest
1.每当建立一个activity,都需要在这个文件中定义:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Helloworld">
<activity
android:name=".MainActivity"
android:exported="true" />
2.打开App时的初始界面:
<activity
android:name=".Register"//小心那个点不能少
android:exported="true">R
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
关于警示
相关代码:Toast.makeText(register.this, "请输入数据。", Toast.LENGTH_SHORT).show();但一般是伴随if语句使用。
关于输入框样式
drawable文件:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="20dp"/>
<stroke
android:width="5dp"
android:color="#FFFFFF"/>
</shape>//圆角框