我有一个片段来替换另一个片段.我想指定动画.但动画被忽略了.
transaction.replace(R.id.my_fragment, newFrag);
transaction.addToBackStack(null);
transaction.setCustomAnimations(R.anim.slide_in_up, R.anim.slide_out_up);
Run Code Online (Sandbox Code Playgroud)
slide_in_up
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromYDelta="0%p"
android:toYDelta="100%p" />
Run Code Online (Sandbox Code Playgroud)
slide_out_up
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromYDelta="100%p"
android:toYDelta="0%p" />
Run Code Online (Sandbox Code Playgroud)
我真正想要实现的是让新片段从底部滑入.我的动画被忽略了.什么是缺少的代码?
我有一个EditText
电话myTextview
.我希望软键盘在我点击时显示,EditText
但如果我点击外面则解雇EditText
.所以我使用下面的方法.但是当我在视图外面点击时键盘不会被忽略(我点击了一下TextView
).我该如何修复此代码?
myTextview.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
} else {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myTextview.getWindowToken(), 0);
}
}
});
Run Code Online (Sandbox Code Playgroud) 我有一个号码需要格式化为电话号码.如果我做
PhoneNumberUtils.formatNumber(numStr);
Run Code Online (Sandbox Code Playgroud)
然后我明白了
888-555-1234
Run Code Online (Sandbox Code Playgroud)
但我需要得到的是
(888) 555-1234
Run Code Online (Sandbox Code Playgroud)
我如何获得第二个?有标准的android方式吗?
所以这是我的onCreateView方法:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
View view = inflater.inflate(R.layout.my_view, container, false);
...
return view;
}
Run Code Online (Sandbox Code Playgroud)
而布局本身就是一个LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
Run Code Online (Sandbox Code Playgroud)
由于某种原因,在添加行后getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
,对话框缩小以包装内容; 实际上,其中一个TextView被强制将其一行包装成两行.我希望Dialog填充屏幕的宽度,保存我指定的一些边距.
我在 android 中使用 SearchView。当我第一次登陆页面时,所有可见的是搜索图标。然后当我单击该图标时,就会出现 EditText。如何让 EditText 从一开始就可见?这是我的 xml:
<SearchView
android:id="@+id/search"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:queryHint="@string/search_hint"
android:textSize="16sp" />
Run Code Online (Sandbox Code Playgroud) 我需要创建一个需要几天和几个月的方法,添加两个,然后返回结果天数.
public int addMonthsToDays(int months, int days);//interface
Run Code Online (Sandbox Code Playgroud)
我想使用joda DateTime,但没有办法获得总天数.这是一个示例实现:
public int addMonthsToDays(int months, int days){
DateTime dateTime = new DateTime().plusDays(days).plusMonths(months);
return // what do I return?
}
Run Code Online (Sandbox Code Playgroud)
附加说明
我知道有些人会误解上述内容并提出一些问题,所以在预料之中:
public int addMonthsToDays(int months, int days)
并从今天起返回新的天数.我有很多孩子的FrameLayout.其中一个孩子是LinearLayout.我想要LinearLayout的宽度,match_parent
但大约90%左右; 这意味着我想添加某种paddingLeft/Right
或margingLeft/Right
.但是当我添加填充或边距时,它不会应用于图形布局.我该怎么做呢?
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/blue" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:background="@color/red"
android:marginLeft="20dp"
android:marginRight="20dp"
android:orientation="vertical" >
....
Run Code Online (Sandbox Code Playgroud)