Android开发中的一些小寄巧

自己练习中收藏的一些重要的东西,记录一下方便使用。

Android去掉Button自带的阴影

style=”?android:attr/borderlessButtonStyle”
<Button
android:id="@+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMessage"
style="?android:attr/borderlessButtonStyle" />

Android设置Spinner控件的文字居中显示

android:textAlignment="center"

SimpleCursorAdapter中显示layout中的图片:

只需要将图片格式改为bmp

listViewAdapter = new SimpleCursorAdapter(this,
                R.layout.item_list,
                result,
                new String[]{"payer","type", "date", "ps","money"},
                new int[]{R.id.payershow,R.id.typeshow, R.id.dateshow2, R.id.psshow,R.id.moneyshow},
                CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
        //3.视图加载适配器
        listView.setAdapter(listViewAdapter);

 Android app 去除顶部蓝色导航栏(Action Bar)

http://t.csdn.cn/ZE0tghttp://t.csdn.cn/ZE0tg

实现RadioButton切换图片

final RadioButton five = findViewById(R.id.radio);//获取button
Drawable myImage = res.getDrawable(R.drawable.home);//获取资源图片
five.setCompoundDrawablesWithIntrinsicBounds(null, myImage, null, null);//四个属性分别代表drawleft drawtop...

实现从fragment 跳转到Activity 

实现从fragment 跳转到Activityhttp://t.csdn.cn/ywRwZ

自定义字体

http://t.csdn.cn/XuEQChttp://t.csdn.cn/XuEQC

 折腾了一晚上的保存fragment的状态,刚开始用的replace就不行,后面改成了用add和hide就可以了。我是先添加了所有的页面,然后再隐藏,通过按钮点击事件来显示具体的页面。所以为什么2022了,Android的fragment还是不能像activity一样自动保存状态呢?我不理解,就是给我增加难度。

group.setOnCheckedChangeListener(
                new RadioGroup.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
                        //设置按钮状态图片为点击前的样式
                        five.setCompoundDrawablesWithIntrinsicBounds(null, geren_grey,null,null);
                        //隐藏所有的页面
                        getSupportFragmentManager().beginTransaction()
                                .hide(first)
                                .commit();
                        getSupportFragmentManager().beginTransaction()
                                .hide(second)
                                .commit();
                        getSupportFragmentManager().beginTransaction()
                                .hide(third)
                                .commit();
                        getSupportFragmentManager().beginTransaction()
                                .hide(forth)
                                .commit();
                        getSupportFragmentManager().beginTransaction()
                                .hide(unlogin)
                                .commit();

                        if (one.isChecked()){
                            // 显示页面1
                                getSupportFragmentManager().beginTransaction()
                                        .show(first)
                                        .addToBackStack(null)
                                        .commit();
                        }
                        else if (two.isChecked()){
                            getSupportFragmentManager().beginTransaction()
                                    .show(second)
                                    .addToBackStack(null)
                                    .commit();
                        }
                        else if (three.isChecked()){
                            getSupportFragmentManager().beginTransaction()
                                    .show(third)
                                    .addToBackStack(null)
                                    .commit();
                        }
                        else if (four.isChecked()){
                            getSupportFragmentManager().beginTransaction()
                                    .show(forth)
                                    .addToBackStack(null)
                                    .commit();
                        }
                        else if (five.isChecked()){

                            five.setCompoundDrawablesWithIntrinsicBounds(null, geren_blue,null,null);

                            getSupportFragmentManager().beginTransaction()
                                    .show(unlogin)
                                    .addToBackStack(null)
                                    .commit();
                        }
                    }
                });

在指定Activity中隐藏顶部导航栏 

ActionBar actionbar = getSupportActionBar();
actionbar.hide();

点击一个页面就要创建一个activity。感觉太多了,查找一下怎么解决。确实通过传递数据的方法可以解决,可以不用一个页面写一个activity。

如何在 Android 中为不同的内容使用相同的 Activity? https://qa.1r1g.com/sf/ask/2634882701/

【Android开发】intent.putExtra()方法参数详解及示例https://www.jianshu.com/p/8a9b84df5018

商品展示可以用RecyclerView和Cardview

RecyclerView基本介绍https://www.baidu.com/link?url=-ZI_5822FRW4Ww8YG7WQY07MVc1TYyvSRNLQj4HFSk46Nf3PKcCPJR3LzmcPU67O&wd=&eqid=890aa7ff00000d4e000000036382fdeb

在android中实现RecyclerView并显示动态数据?icon-default.png?t=M85Bhttp://t.csdn.cn/UZTd8 

CardView学习和使用http://t.csdn.cn/TlgzM

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值