【问题标题】:How to create Android custom titlebar如何创建 Android 自定义标题栏
【发布时间】:2013-03-16 19:06:54
【问题描述】:

我尝试在 Android 上构建应用程序。 我是 Android 新手。 但我不知道如何构建这样的标题栏。 因此,我们可以使用选项卡按钮为应用程序命名,例如 Seesmic 和 Komutta。 谁能帮我给我答案或只是该教程的链接?

谢谢。

https://lh6.ggpht.com/Hf6XKfa9K0B-CvlV6tD6qj2Yt8wJcyJ7wa8vE9BVkBbUDm0Y2pqOxgxVf7auQgXrh0gR

https://lh4.ggpht.com/rwceS5ZK1IZkHHCVixbaXlsHXwstpmIO888aMC4U0uD2oa54NiGvphcp_penGK9Q9WE

很抱歉我无法上传图片,所以我只能提供该图片的链接。

【问题讨论】:

    标签: android customization titlebar


    【解决方案1】:

    这被称为“动作栏”,你可以从Android 3.0开始自然地获取它,或者在早期版本的androidhere.上获取代码来完成它

    【讨论】:

      【解决方案2】:

      android 网站有一个演示,您可以查看CustomTitlehow-to-create-custom-window-title-in-android

      【讨论】:

      • 感谢您的建议,但我的应用程序刚开始时它仍然出现标题,但时间不长。我们如何解决这个问题?
      【解决方案3】:
      1. 创建一个新项目并将您的主要活动命名为“MyActivity”
      2. 转到 res - drawable 并创建一个新的 xml 文件并将其命名为“custom_title_background”并输入以下代码:

        <item android:top="20dp">
            <shape android:shape="rectangle">
                <gradient android:angle="90" android:endcolor="#9eacbf" android:startcolor="#8296af">
            </gradient></shape>
        </item>
        

      这个drawable将用于从custom_title_bar设置背景(从第3步开始)并从custom_title_style设置windowTitleBackgroundStyle(从第4步开始)

      1. 转到 res-layout 并创建一个新的 xml 并将其命名为“custom_title_bar”。在这里,您将创建一个带有文本视图的布局,如下代码所示:

        <TextView android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:textSize="16sp"
                  android:textColor="@android:color/white"
                  android:textStyle="bold"
                  android:id="@+id/custom_title_text"
                  android:layout_centerInParent="true"
                  android:shadowColor="@android:color/black"
                  android:shadowRadius="3"/>
        

      2. 转到 res - values 并创建一个新的 xml 文件并将其命名为 custom_title_style。在这里,您将通过覆盖现有主题来创建一个新主题。下面的样式名称“custom_title_theme”将用于清单文件以“激活”新主题。

        40dp @drawable/custom_title_background

      3. 现在转到 AndroidManifest.xml 文件并将新主题放入应用程序标签中。

      ? 1

      1. 在这最后一步,你必须进入 MyActivity 类并输入以下代码:

        导入android.app.Activity; 导入android.os.Bundle; 导入android.view.Window; 导入android.widget.TextView;

        公共类 MyActivity 扩展 Activity {

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
        
            //this must be called BEFORE setContentView
            requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        
            setContentView(R.layout.main);
        
            //this must bew called AFTER setContentView
            getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_bar);
        
            //set the title
            TextView textView = (TextView)findViewById(R.id.custom_title_text);
            textView.setText("Custom Title");
        }
        

        }

      【讨论】:

        猜你喜欢
        • 2011-08-10
        • 2011-03-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-11-01
        • 2014-07-05
        • 1970-01-01
        相关资源
        最近更新 更多