首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >actionbar与地铁设计

actionbar与地铁设计
EN

Stack Overflow用户
提问于 2015-12-11 12:09:07
回答 2查看 123关注 0票数 0

我一直在努力解决所有这些向后兼容和支持库的问题,并且非常希望得到一些帮助。

我想实现一个项目,在顶部有一个动作栏,用于导航和设置之类的东西,我想使用地铁设计主题。我不在乎向后兼容。

我的问题是我该怎么做?我需要什么课程和主题?

到目前为止这是我的密码。在"LogIn“活动中,我看到了ActionBar,但在”注册“活动中,我没有看到。

LogIn.xml:

代码语言:javascript
复制
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_horizontal"
        android:orientation="vertical"

        tools:context=".LogIn.LoginActivity">

        <!-- Login progress -->
        <ProgressBar
            android:id="@+id/login_progress"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:visibility="gone" />

        <RelativeLayout
            android:id="@+id/login_form"

            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <Button
                android:id="@+id/login_BTN_new_registration"
                android:text="New Registration"
                style="@style/BoldCenterText"
                android:layout_above="@+id/email_login_form"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <LinearLayout
                android:id="@+id/email_login_form"
                android:layout_centerInParent="true"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <android.support.design.widget.TextInputLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <AutoCompleteTextView
                        android:id="@+id/email"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="@string/prompt_username"
                        android:inputType="text"
                        android:maxLines="1"
                        android:singleLine="true" />

                </android.support.design.widget.TextInputLayout>

                <android.support.design.widget.TextInputLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <EditText
                        android:id="@+id/password"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="@string/prompt_password"
                        android:imeActionId="@+id/login"
                     android:imeActionLabel="@string/action_sign_in_short"
                        android:imeOptions="actionUnspecified"
                        android:inputType="textPassword"
                        android:maxLines="1"
                        android:singleLine="true" />

                </android.support.design.widget.TextInputLayout>
            </LinearLayout>

            <LinearLayout
                android:layout_above="@+id/email_sign_in_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="16dp">

                <TextView
                    android:text="Auto login"
                    style="@style/CenterText"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    />

                <Switch
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:checked="true"/>


            </LinearLayout>

            <Button
                android:id="@+id/email_sign_in_button"
                style="@style/BoldCenterText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Log In"
                android:layout_alignParentBottom="true"
                android:textStyle="bold" />
        </RelativeLayout>
    </LinearLayout>

Registration.xml:

代码语言:javascript
复制
<?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="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".LogIn.RegistrationActivity">

    <ProgressBar
        android:id="@+id/registration_PB_progress"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:visibility="gone" />

    <RelativeLayout
        android:id="@+id/registration_LL_registration_form"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            style="@style/BoldCenterText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:text="Create new account" />


        <LinearLayout

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:orientation="vertical">

            <TextView
                style="@style/BoldCenterText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Required" />

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <AutoCompleteTextView
                    android:id="@+id/registration_ACTV_username"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/prompt_username"
                    android:inputType="text"
                    android:maxLines="1"
                    android:singleLine="true" />

            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <EditText
                    android:id="@+id/registration_ET_password1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/prompt_password"
                    android:inputType="textPassword"
                    android:maxLines="1"
                    android:singleLine="true" />

            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <EditText
                    android:id="@+id/registration_ET_password2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/prompt_password_repeat"
                    android:inputType="textPassword"
                    android:maxLines="1"
                    android:singleLine="true" />

            </android.support.design.widget.TextInputLayout>

            <TextView
                style="@style/BoldCenterText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Optional" />

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <EditText
                    android:id="@+id/registration_ET_email"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/prompt_email"
                    android:inputType="textEmailAddress"
                    android:maxLines="1"
                    android:singleLine="true" />

            </android.support.design.widget.TextInputLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <TextView
                    android:text="Background color"
                    android:textSize="18sp"
                    android:paddingLeft="13sp"
                    android:gravity="center_vertical"
                    android:layout_weight="0.5"
                    android:layout_width="0dp"
                    android:layout_height="match_parent" />

                <Spinner
                    android:padding="0sp"
                    android:id="@+id/registration_S_color"
                    android:layout_weight="0.5"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:spinnerMode="dropdown" />
            </LinearLayout>
        </LinearLayout>

        <Button
            android:id="@+id/registration_BTN_register"
            style="@style/BoldCenterText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:padding="0sp"
            android:text="Register" />
    </RelativeLayout>
</LinearLayout>

Manifest.xml:

代码语言:javascript
复制
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity
        android:name=".LogIn.SplashScreen2"
        android:noHistory="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".LogIn.LoginActivity"
        android:label="@string/title_activity_login"
        android:noHistory="true" />
    <activity android:name=".Main.MainActivity" />
    <activity
        android:name=".LogIn.RegistrationActivity"
        android:label="Registration"
        android:noHistory="true" />
</application>

AppTheme:

代码语言:javascript
复制
<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>
</style>

为什么我没有在注册活动中看到ActionBar呢?

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-12-11 12:16:22

使用AppCompat活动扩展您的活动,然后您就可以获得所需的结果。

代码语言:javascript
复制
public class RegistrationActivity extends AppCompatActivity {}

有关您的信息,如果要更改操作栏标题和副标题:

代码语言:javascript
复制
if(getSupportActionBar()!=null{
getSupportActionBar.setTitle("Register");
getSupportActionBar.setSubTitle("SUb Title");
}

以上方法仅在您使用AppCompatActivity扩展了活动时才能工作。

如果您需要进一步的帮助,请在下面评论

票数 1
EN

Stack Overflow用户

发布于 2015-12-11 12:17:00

我想通了。

我忘记在我的RegistrationActivity.java中扩展RegistrationActivity.java

对不起,浪费你的时间:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34223235

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档