zoukankan      html  css  js  c++  java
  • android 如何使用手机厂商封装系统相应版本的样式

    main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        tools:context=".MainActivity" >
    
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello" />
    
        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button"
            android:onClick="button" />
    
    </LinearLayout>

    MainActivity.java

    public class MainActivity extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
        }
        
        public void button(View v){
            new AlertDialog.Builder(MainActivity.this)  
            .setIcon(android.R.drawable.ic_menu_info_details)  
            .setTitle("金软Office[试用版]")  
            .setPositiveButton("确定", new DialogInterface.OnClickListener() {  
                @Override  
                public void onClick(DialogInterface dialog, int which) {  
                    // TODO Auto-generated method stub  
                }  
            }).show();  
        }
    }

    注意:

    如果在AndroidManifest.xml定义如下

    <uses-sdk android:minSdkVersion="7" />

    效果图为:

    如果是如下定义

    <uses-sdk android:minSdkVersion="7"android:targetSdkVersion="15"/>

    效果图:

    测试机为HTC G14

    后面发现添加

    android:theme="@android:style/Theme.NoTitleBar"

    后,图片为

    为了完成最初目的:

    styleAndroidManifest.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <resources>
        <style name="concealTitle">
            <item name="android:windowNoTitle">true</item>
        </style>
    </resources>

    定义完了一个style,接下来就是在AndroidManifest.xml中使用了:

    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/concealTitle">

    最终效果实现:

  • 相关阅读:
    Shell之海量数据处理grep,cut,awk,sed
    [Linux] Migrate plugins and setting for vim
    [C++] Template
    c++ Dynamic Memory (part 2)
    Image process
    c++ Dynamic Memory (part 1)
    [Algorithm] A* Search Algorithm Basic
    [C++] Solve "No source available for main()" error when debugging on Eclipse
    [C++] Solve "Cannot run program "gdb": Unknown reason" error
    [C++] Solve "Launch Failed. Binary not found." error on Eclipse
  • 原文地址:https://www.cnblogs.com/sishuiliuyun/p/3065279.html
Copyright © 2011-2022 走看看