代码之家  ›  专栏  ›  技术社区  ›  Marcel Alexandru

如何制作一个只有左上角和右下角的搜索栏?

  •  0
  • Marcel Alexandru  · 技术社区  · 6 年前

    如何制作左上角和右下角圆角的搜索栏?

    下面的代码使它变得全面,但我想成为这样的人 here 在此图像中。 如果有人能帮我,我会很高兴的^^

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
        <FrameLayout
            android:id="@id/search_bar_container"
            android:background="@*android:color/primary_material_dark"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            app:cardElevation="50.0dip">
    
            <android.support.v7.widget.CardView
                android:id="@id/search_bar"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/search_bar_margin"
                app:cardCornerRadius="24.0dip"
                app:cardElevation="50.0dip"
                app:cardBackgroundColor="@*android:color/primary_material_dark">
    
                <Toolbar
                    android:id="@id/search_action_bar"
                    android:theme="?android:attr/actionBarTheme"
                    android:contentInsetStartWithNavigation="64dp"
                    android:navigationIcon="@drawable/ic_search_24dp"
                    android:navigationContentDescription="@string/search_menu"                
                    android:background="@color/background_floating_material_dark"
                    android:layout_width="fill_parent"
                    android:layout_height="@dimen/search_bar_height"
                    android:titleTextAppearance="@style/TextAppearance.SearchBar"
                    android:title="@string/search_menu" />
            </android.support.v7.widget.CardView>
        </FrameLayout>
        <FrameLayout
            android:id="@id/main_content"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </LinearLayout>
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Sahil Manchanda    6 年前

    创建一个背景。drawable文件夹中的xml

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
    <corners
    android:topLeftRadius="19dp"
    android:topRightRadius="0dp"
    android:bottomLeftRadius="0dp"
    android:bottomRightRadius="16dp"
    />
    <solid
    android:color="#002f00"
    />
    <size
    android:width="270dp"
    android:height="60dp"
    />
    <stroke
    android:width="2dp"
    android:color="#00fe00"
    />
    </shape>
    

    使用此绘图设置编辑文本的背景。更改半径值以获得所需的半径。

    输出如下

    enter image description here