标签: android-xml

Android TextInput 提示文本颜色

我有这个TextInputLayoutEditText我的文本提示是黑色,我想更改它。

顺便说一下,当提示出现在顶部时,它的颜色是白色的

 <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:hintTextAppearance="@style/TextAppearance.App.TextInputLayout">

            <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:textColor="@android:color/white"
                android:textColorHint="@android:color/white" />

        </android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)

风格

<style name="TextAppearance.App.TextInputLayout" parent="@android:style/TextAppearance">
    <item name="android:textColor">@android:color/white</item>
    <item name="android:textColorHint">@android:color/white</item>
    <item name="colorPrimary">@android:color/white</item>
    <item name="colorAccent">@android:color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

java xml android android-xml

3
推荐指数
1
解决办法
1万
查看次数

按后退按钮显示相同的活动

我有两项活动。

  1. 登录活动
  2. 主屏幕

我也有一个带有此设置的启动屏幕:

<activity android:name=".SplashScreen"
            android:theme="@style/AppTheme.NoActionBar"
            android:noHistory="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)

然后,启动屏幕使用以下代码将用户转移到主屏幕:

Intent intent = new Intent(SplashScreen.this, HomeScreen.class);
Run Code Online (Sandbox Code Playgroud)

在主屏幕活动中,我检查用户是否已经登录。如果他没有登录,我将他转移到 LoginActivity:

 mAuthListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(FirebaseAuth firebaseAuth) {
                if(firebaseAuth.getCurrentUser() == null)
                {
                    Intent intent = new Intent(HomeScreen.this,LoginActivity.class);
                    Toast.makeText(HomeScreen.this,"H>L on no login",Toast.LENGTH_LONG).show(); //toast to show me why my app is in infinite loop
                    startActivity(intent);
                }
            }
        };
Run Code Online (Sandbox Code Playgroud)

在 LoginActivity 上,我有一个简单的登录按钮,它使用 FireBase Google 身份验证。另外,我检查用户是否已经登录,如果是,则他已转移到 HomeScreen Activity:

mAuthListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public …
Run Code Online (Sandbox Code Playgroud)

java android android-xml android-activity

3
推荐指数
1
解决办法
3531
查看次数

如何在 Android 中继续显示底部导航菜单标题?

我在底部导航视图中有 5 个图标,当我单击菜单时,我可以看到菜单的标题,如果我单击另一个图标,前一个的标题就会消失。我想继续以 XML 形式显示所有菜单的标题。我该怎么做?

这是我在活动 XML 中的代码。

 <androidx.coordinatorlayout.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottomNV"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:backgroundTint="@color/light_gray"
        app:itemIconTint="@color/black"
        app:itemTextColor="@color/black"
        app:menu="@menu/bottom_navigation_menu"/>


</androidx.coordinatorlayout.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

这是一个菜单资源文件。

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:id="@+id/bottom_menu_home"
    android:enabled="true"
    android:icon="@drawable/bottom_home_inactive"
    android:title="@string/bottom_menu_home" />

<item
    android:id="@+id/bottom_menu_search"
    android:enabled="true"
    android:icon="@drawable/bottom_search_inactive"
    android:title="@string/bottom_menu_search" />

<item
    android:id="@+id/bottom_menu_message"
    android:enabled="true"
    android:icon="@drawable/bottom_message_inactive"
    android:title="@string/bottom_menu_message" />

<item
    android:id="@+id/bottom_menu_reservation"
    android:enabled="true"
    android:icon="@drawable/bottom_reservation_inactive"
    android:title="@string/bottom_menu_reservation" />

<item
    android:id="@+id/bottom_menu_myInfo"
    android:enabled="true"
    android:icon="@drawable/bottom_myinfo_inactive"
    android:title="@string/bottom_menu_myInfo" />
Run Code Online (Sandbox Code Playgroud)

android android-xml bottomnavigationview material-components-android android-bottomnavigationview

3
推荐指数
1
解决办法
2788
查看次数

将视图放置在多行 TextView 的末尾

我想在动态末尾添加一个自定义视图(包含文本和图标的视图),TextView如下图所示。

提前致谢。

在此输入图像描述

android android-layout android-xml android-view

3
推荐指数
1
解决办法
1234
查看次数

Android:在样式xml文件中包含内容描述

在Eclipse中开始使用Android Lint工具后,我收到了许多新警告。其中之一是说我的ImageViews缺少contentDescription。

对于常规的ImageView,我这样做是这样的,并且效果很好:

<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:contentDescription="@string/imgViewDesc"
    ....
</ImageView>
Run Code Online (Sandbox Code Playgroud)

但是,如果我有一个使用样式xml文件的ImageView,如下所示:

<ImageView
    style="@style/TitleBarLogo"
    android:src="@drawable/title_logo" />
Run Code Online (Sandbox Code Playgroud)

如果我在styles.xml中具有以下内容:

<style name="TitleBarLogo">
    <item name="android:contentDescription">@string/imgViewDesc</item>
    ....
</style>
Run Code Online (Sandbox Code Playgroud)

警告并不会消失。

有没有什么办法解决这一问题?

android android-xml

2
推荐指数
1
解决办法
2499
查看次数

只需编写一次方法,然后在应用程序中的"android:onClick"中访问它

我的申请表中有一个标题栏.标题栏有一个按钮.点击该按钮,我显示信息活动.现在,据我所知,android:onClick需要在活动内部引用一个公共方法,该方法设置了xml setContentView().现在,由于单击按钮的逻辑在整个应用程序中都是相同的,所以我想要的是,我只会说这个方法showInfoScreen(View view)并将其放在那个按钮onClick属性中.我不需要在任何地方写相同的方法.可能吗?

android onclick android-xml

2
推荐指数
1
解决办法
246
查看次数

通过XML向操作栏添加选项卡

我知道可以使用/ res/menu目录中的XML文件将MenuItems添加到ActionBar中.

我一直在寻找一个如何使用XML将Tabs添加到ActionBar但没有任何成功的示例.

我只找到了一种方法来执行此操作:actionbar.newTab()方法,但我不想在代码中执行此操作...

你有什么主意吗?

谢谢.

android android-layout android-xml

2
推荐指数
1
解决办法
1518
查看次数

如何更改操作栏的颜色(actionbarsherlock)

如何更改actionbar(actionbarsherlock)的颜色?

我已经尝试过以下代码,但没有运气.

<style name="MyTheme.ActionBarStyle" parent="Widget.Sherlock.ActionBar">
    <item name="background">#ffffffff</item>
</style>

<style name="Theme.SherlockCustom" parent="@style/Theme.Sherlock.Light">
    <item name="actionBarStyle">@style/MyTheme.ActionBarStyle</item>
</style>
Run Code Online (Sandbox Code Playgroud)

+还有一件事,我在下面添加子菜单.这个按钮的背景颜色也是白色(因为Sherlock主题).我能改变那些颜色吗?

    SubMenu sub = menu.add("abcd");
    sub.add(0, 1, 0, "Default");
    sub.add(0, 2, 0, "Light");
    sub.add(0, 3, 0, "Light (Dark Action Bar)");
    sub.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
Run Code Online (Sandbox Code Playgroud)

android android-layout android-xml actionbarsherlock android-actionbar

2
推荐指数
1
解决办法
5707
查看次数

呼叫需要API级别16(当前最小值为14)

我的代码中有这一行:

linearLayout.setBackground(drawable);
Run Code Online (Sandbox Code Playgroud)

setBackground() 显示以下错误:

呼叫需要API级别16(当前最小值为14)

这是什么意思?

我可以提高我的API级别吗?

更高/更低的API级别意味着什么?

如果API级别更高,是否会限制我的应用可以使用的设备数量?

android android-layout android-xml android-fragments android-activity

2
推荐指数
2
解决办法
9883
查看次数

Android版式:与Facebook应用类似的评论活动

我一直在看Facebook评论活动:

脸书

我一直想知道他们如何设法使edittext的大小从一行增加到最多4行,与此同时,包含这些帖子的recyclerview也向上调整并减小了大小。当您输入文字时,这会自动发生。

我正在尝试通过执行以下操作自己复制其布局,但我不能显示多于2行。它一直将自身限制为“发送”箭头的大小,但在下面的示例中,edittext永远不会超过recyclerview。

我的脸书

以下是我的xml布局代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@color/white"
    >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/like_box"
        android:text="Number of Likes goes here"
        android:maxLines="1"
        android:minLines="1"
        android:layout_margin="16dp"
        />

    <View
        android:layout_width="match_parent"
        android:layout_height="0.2dp"
        android:id="@+id/divider"
        android:layout_below="@+id/like_box"
        android:background="@color/half_black"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/my_recycler_view"
        android:layout_below="@+id/divider"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/commenttext" />

    <View
        android:layout_width="match_parent"
        android:layout_height="0.2dp"
        android:id="@+id/divider2"
        android:layout_below="@+id/my_recycler_view"
        android:background="@color/half_black"/>


        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/commenttext"
            android:layout_toLeftOf="@+id/send"
            android:background="@null"
            android:paddingLeft="16dp"
            android:textSize="16sp"
            android:hint="Add a comment here"
            android:layout_alignTop="@+id/send"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentBottom="true" />

        <ImageView
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:id="@+id/send"
            android:src="@drawable/ic_action_send_now"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

有谁知道正确的xml布局代码是什么,以确保输入文本时,edittext和recyclerview都向上调整?我认为这只是简单的事情,例如将“ wrap_content”设置为我已经完成的edittext,但仍然无法正确调整。

Anoop M的答案似乎与我想做的最接近,但是recyclerview的调整不正确-请参见下图。想象一下,如果屏幕的蓝色部分充满了文本,那么当您输入4行以上时,edittext最终将文本隐藏在蓝色部分中。edittext似乎遍历了recyclerview。在Facebook应用程序上不会发生这种情况,当edittext大小增加时,随着recyclerview向上调整,注释将完全显示。

Anoop M的答案

android facebook android-layout android-xml

2
推荐指数
1
解决办法
4841
查看次数