Android开发小知识

时间:2023-03-10 04:47:02
Android开发小知识

修改Android app图标(Android Studio)

1.  res\drawable 放置icon.png(此图片是你需要修改的图标);

2.  修改AndroidManifest.xml : android:icon="@drawable/icon"

3.  编译运行即可。

去除Android app标题栏(Android Studio)

res-->values-->styles.xml,注意红色部分的值

<resources>

    <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>

按Enter键处理事情

监听Enter的事件,编写Enter的事件响应。设置文本框的OnKeyListener,当keyCode ==KeyEvent.KEYCODE_ENTER的时候,表明Enter键被按下,就可以编写自己事件响应功能了

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText msg = (EditText)findViewById(R.id.msg );
msg .setOnKeyListener(OnKey);
} OnKeyListener onKey=new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if(keyCode == KeyEvent.KEYCODE_ENTER){
//这里写发送信息的方法
}
}

添加Application闪退解决

在使用application的过程中,需要在AndroidMainfest.xml中注册application;例如:

<application
     android:name=".APPStore"
APPStore为继承自application的类,否则会出现闪退。