小编vis*_*was的帖子

如何在android中的多个编辑文本上添加文本观察器?

我有一个活动,其中包含两个编辑文本,并且TextWatcher该活动中有一个单独实现的活动。我想创建一个实现该编辑文本的TextWatcherTextWatcher。我该如何执行该代码:-

private TextWatcher getmWatcher = new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }

    @Override
    public void afterTextChanged(Editable s) {
        checkFieldsForEmpty();
    }
};
private TextWatcher mWatcher = new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) …
Run Code Online (Sandbox Code Playgroud)

android android-textwatcher

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

如何在android中编辑文本中添加"+91"并删除"+91"?

我有一个活动,其中我有移动编辑文本我想要的当用户输入手机号码我想在号码前添加"+91",当用户删除完整号码我也想删除"+91".我怎么能这样做

TextWatcher m_MobileWatcher = new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }

    @Override
    public void afterTextChanged(Editable s) {
        if (!s.toString().contains("+91")) {
            m_InputMobie.setText("+91" + s.toString());
            Selection.setSelection(m_InputMobie.getText(), m_InputMobie.getText().length());
        }
    }
};
Run Code Online (Sandbox Code Playgroud)

android

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

如何在Android中删除默认操作栏并添加工具栏?

我正在开发一个具有窗口默认操作栏的应用程序,但是我想删除该应用程序栏并添加工具栏。我该如何添加

删除操作栏的代码:

 <activity
        android:name=".CMainActivity"
        android:screenOrientation="portrait"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar"
       />
Run Code Online (Sandbox Code Playgroud)

我正在扩展AppCompatActivity

// navigation bar code
    m_Drawer = (DrawerLayout) findViewById(R.id.drawer_layout);//finding id of drawerlayout
    s_drawerToggle = new ActionBarDrawerToggle(
            this, m_Drawer, m_Toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    m_Drawer.setDrawerListener(s_drawerToggle);
    m_Drawer.setScrimColor(getResources().getColor(android.R.color.transparent));
    s_drawerToggle.syncState();

<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

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

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"

        android:titleTextColor="#FFFF"
        app:layout_scrollFlags="scroll|enterAlways"
        tools:ignore="UnusedAttribute">
    </android.support.v7.widget.Toolbar>

    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/primary"
        android:minHeight="?attr/actionBarSize"
        app:tabIndicatorColor="@android:color/white"
        app:tabIndicatorHeight="2dp"
        app:tabTextAppearance="?android:textAppearanceMedium"
        tools:ignore="UnusedAttribute"/>

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</LinearLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer"
    tools:ignore="PrivateResource"/>
Run Code Online (Sandbox Code Playgroud)

android android-actionbar android-toolbar

0
推荐指数
1
解决办法
6391
查看次数