Android 常用代码

本文介绍了如何在Android应用中配置自定义的主题样式,包括去除标题栏、实现全屏显示等设置,并提供了获取应用版本号、显示Toast消息、获取IMEI号码等实用代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <!--无导航栏 -->
        <item name="windowActionBar">false</item>
        <!--无标题栏 -->
        <item name="windowNoTitle">true</item>
        <!--全屏-->
        <item name="android:windowFullscreen">true</item>
    </style>

</resources>
    // 取得应用版本号 
    public static String GetVersion (Context context) {
           try {
              PackageInfo manager = context.getPackageManager().getPackageInfo(
                        context.getPackageName(), 0);
               return manager. versionName;
          } catch (NameNotFoundException e) {
               return "Unknown";
          }
     }
     // 去除标题栏 去除title
      //去除标题栏
     this.requestWindowFeature(Window.FEATURE_NO_TITLE);
     //去除状态栏
     this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
     // showToast
    public static void showToast( final String toast, final Context context)
    {
     new Thread( new Runnable() {
               @Override
               public void run() {
                   Looper. prepare();
                   Toast. makeText(context, toast, Toast.LENGTH_SHORT).show();
                   Looper. loop();
              }
          }).start();
    }
     // 获取手机设备号  
public static String getImei(Context context, String imei) {
           try {
              TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE );
              imei = telephonyManager.getDeviceId();
          } catch (Exception e) {
              Log. e(ExampleUtil.class.getSimpleName(), e.getMessage());
          }
           return imei;
     }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值