public class LoginActivity extends ActionBarActivity {
protected void onCreate(Bundle savedInstanceState) {
try
{
super.onCreate(savedInstanceState);
System.out.println("here");
setContentView(R.layout.activity_login);
Toolbar mToolBar = (Toolbar)findViewById(R.id.toolbar);
if(mToolBar != null)
{
setSupportActionBar(mToolBar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
mToolBar.setNavigationOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//What to do on back clicked
finish();
}
}); //this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
setTitle("LOGIN");
}
catch(Exception e)
{
System.out.println(" "+e.getMessage());
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:minHeight="56dp"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:titleTextAppearance="#style/ToolbarTitle" />
<RelativeLayout
android:id="#+id/lais"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/toolbar"
android:orientation="horizontal" >
<ImageView
android:id="#+id/image1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:src="#drawable/ic_logo"
android:padding="10dp" >
</ImageView>
</RelativeLayout>
<ScrollView
android:id="#+id/scrollV"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/lais"
android:fadingEdge="none"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="20dp"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="Username"
android:textColor="#android:color/white"
android:textSize="14sp" />
<EditText
android:id="#+id/usernameField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:drawableLeft="#drawable/bg_username"
android:drawablePadding="5dp"
android:inputType="text"
android:singleLine="true" >
<requestFocus />
</EditText>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="Password"
android:textColor="#android:color/white"
android:textSize="14sp" />
<EditText
android:id="#+id/passwordField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:drawableLeft="#drawable/bg_password"
android:drawablePadding="5dp"
android:ems="10"
android:inputType="textPassword" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="#+id/submitBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginBottom="10dp"
android:layout_weight="1"
android:text="Submit"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
I get the following error android.support.v7.internal.widget.ContentFrameLayout cannot be cast to android.support.v7.internal.widget.NativeActionModeAwareLayout. I still cannot figure out what the error is bout.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/RelativeLayout12"
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="wrap_content"
android:background="#android:color/white"
android:minHeight="56dp"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:titleTextAppearance="#style/ToolbarTitle" />
Try like above
Related
Problem :
unable to find solution for remove blank space layout
Image :
GIF Image :
Main screen is my HomeFragment in which i use CollapsingToolbarLayout ,NestedScrollView and ViewPager and in ViewPager load 3 Fragments code is below
private void setupViewPager(ViewPager viewPager) {
HomeFragment.ViewPagerAdapter adapter = new HomeFragment.ViewPagerAdapter(getChildFragmentManager());
adapter.addFragment(new InstantFragment(), "Instant");
adapter.addFragment(new LimitFragment(), "Limit");
adapter.addFragment(new StopFragment(), "Stop");
viewPager.setAdapter(adapter);
}
Here is my fragment_home.xml code
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/ll_home_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#mipmap/ic_app_background">
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleGravity="top"
app:expandedTitleMarginStart="10dp"
app:expandedTitleMarginTop="20dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<LinearLayout
android:id="#+id/llChild"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<RelativeLayout
android:id="#+id/llview_relative"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:gravity="center"
android:orientation="horizontal">
<Spinner
android:id="#+id/spinner_currency"
android:layout_width="200dp"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="20dp" />
<Button
android:id="#+id/btndeposit"
android:layout_width="80dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="#dimen/margin10"
android:layout_marginRight="#dimen/margin20"
android:background="#color/pink"
android:text="Deposit"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="16dp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="256dp"
android:layout_margin="#dimen/margin10"
android:layout_marginTop="#dimen/margin10"
android:orientation="vertical"
android:background="#mipmap/ic_app_background">
<com.github.mikephil.charting.charts.CandleStickChart
android:id="#+id/chart1"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<WebView
android:id="#+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true"
android:scrollbars="none" />
</LinearLayout>
<TextView
android:id="#+id/txt_my_opn_order"
android:layout_marginTop="#dimen/margin10"
android:text="#string/my_open_orders_title"
android:textSize="17sp"
android:fontFamily="#font/poppins_light"
android:textColor="#color/notification_title"
android:layout_marginLeft="#dimen/margin5"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#+id/sub_frame_container"
android:layout_width="match_parent"
android:visibility="gone"
android:animateLayoutChanges="true"
android:layout_height="wrap_content"/>
</LinearLayout>
</android.support.design.widget.CollapsingToolbarLayout>
<TextView
android:layout_marginTop="#dimen/margin10"
android:text="#string/new_orders_title"
android:textSize="17sp"
android:fontFamily="#font/poppins_light"
android:textColor="#color/notification_title"
android:layout_marginLeft="#dimen/margin5"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<com.bacancy.kryptonight.customviews.CustomViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
here is code for CustomViewPager
public class CustomViewPager extends ViewPager {
public CustomViewPager(Context context) {
super(context);
}
public CustomViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int height = 0;
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
int h = child.getMeasuredHeight();
if (h > height) height = h;
}
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
here is 1st Fragment fragment_instant.xml code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#2C2f33"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="#dimen/margin20"
android:layout_marginTop="#dimen/margin10"
android:gravity="center"
android:text="#string/spend_title"
android:textColor="#color/white"
android:textSize="#dimen/margin20" />
<EditText
android:id="#+id/edtspend"
android:layout_width="match_parent"
android:layout_height="#dimen/edittext_height"
android:layout_marginLeft="#dimen/margin20"
android:layout_marginRight="#dimen/margin20"
android:textColor="#color/white"
android:background="#color/edittext_background"
android:hint="Amount"
android:maxLength="20"
android:inputType="number"
android:paddingLeft="#dimen/margin5" />
<TextView
android:id="#+id/txtsubtotal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin20"
android:layout_marginRight="#dimen/margin20"
android:layout_marginTop="#dimen/margin10"
android:visibility="gone"
android:text="#string/subtotal"
android:textColor="#color/textcolor" />
<TextView
android:id="#+id/txtfee"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin20"
android:visibility="gone"
android:text="#string/fee"
android:textColor="#color/textcolor" />
<CheckBox
android:layout_margin="#dimen/margin20"
android:id="#+id/chkisPartialBuy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin20"
android:buttonTint="#color/button_buy"
android:text="#string/is_partial_title"
android:textColor="#color/textcolor"
android:textSize="16dp" />
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_marginLeft="#dimen/margin20"
android:layout_marginRight="#dimen/margin20"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/approx"
android:textColor="#color/textcolor" />
<TextView
android:layout_marginLeft="#dimen/margin10"
android:id="#+id/txtapprox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
android:text="#string/approx_def_price_buy"
android:textColor="#color/textcolor" />
</LinearLayout>
<Button
android:id="#+id/btnbuy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin20"
android:layout_marginRight="#dimen/margin20"
android:layout_marginTop="#dimen/margin30"
android:background="#color/button_buy"
android:text="#string/buy"
android:textColor="#color/white" />
<TextView
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="#dimen/margin20"
android:background="#color/line" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="#dimen/margin20"
android:layout_marginTop="#dimen/margin10"
android:gravity="center"
android:text="#string/sell_title"
android:textColor="#color/white"
android:textSize="#dimen/margin20" />
<EditText
android:id="#+id/edtsell"
android:layout_width="match_parent"
android:layout_height="#dimen/edittext_height"
android:layout_marginLeft="#dimen/margin20"
android:textColor="#color/white"
android:inputType="numberDecimal"
android:layout_marginRight="#dimen/margin20"
android:maxLength="20"
android:background="#color/edittext_background"
android:hint="Amount"
android:paddingLeft="#dimen/margin5" />
<TextView
android:id="#+id/txtsubtotal_sell"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin20"
android:layout_marginRight="#dimen/margin20"
android:layout_marginTop="#dimen/margin10"
android:text="#string/subtotal"
android:visibility="gone"
android:textColor="#color/textcolor" />
<TextView
android:id="#+id/txtfee_sell"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin20"
android:visibility="gone"
android:text="#string/fee"
android:textColor="#color/textcolor" />
<CheckBox
android:layout_margin="#dimen/margin20"
android:id="#+id/chkisPartialSell"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin20"
android:buttonTint="#color/button_sell"
android:text="#string/is_partial_title"
android:textColor="#color/textcolor"
android:textSize="16dp" />
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_marginLeft="#dimen/margin20"
android:layout_marginRight="#dimen/margin20"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/approx"
android:textColor="#color/textcolor" />
<TextView
android:id="#+id/txtapprox_sell"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin10"
android:maxLines="1"
android:ellipsize="end"
android:text="#string/approx_def_price_sell"
android:textColor="#color/textcolor" />
</LinearLayout>
<Button
android:id="#+id/btnsell"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/margin60"
android:layout_marginLeft="#dimen/margin20"
android:layout_marginRight="#dimen/margin20"
android:layout_marginTop="#dimen/margin30"
android:background="#color/button_sell"
android:text="#string/sell"
android:textColor="#color/white" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
i check CustomViewPager class where height set how can we set height current view to WRAP_CONTENT
used tabpane take 120dp height in top.
mainxml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#E0E0E0"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.suranpc.recy.MainActivity">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="120dp"
android:scrollbars="vertical"
/>
</RelativeLayout>
cardview design xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardCornerRadius="3dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:padding="16dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#ffffff"
android:orientation="horizontal"
android:padding="16dp"
>
<TextView
android:id="#+id/firstcardtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="TextView"
android:textColor="#color/colorFontblack"
android:textSize="20dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="60dp"
android:background="#ffffff"
android:orientation="horizontal"
android:padding="4dp"
>
<TextView
android:id="#+id/firstcardtext2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:text="TextView :"
android:textAlignment="center"
android:textColor="#color/colorFontblack"
android:textSize="22dp"
android:textStyle="bold" />
<TextView
android:id="#+id/firstcardtext3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.91"
android:gravity="right"
android:text="TextView"
android:textAlignment="center"
android:textColor="#color/colorPrimaryDark"
android:textSize="22dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="120dp"
android:background="#ffffff"
android:orientation="horizontal"
android:padding="1dp"
>
<TextView
android:id="#+id/firstcardtext4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.92"
android:gravity="left"
android:text="TextView:"
android:textAlignment="center"
android:textColor="#color/colorFontblack"
android:textSize="22dp"
android:textStyle="bold" />
<TextView
android:id="#+id/firstcardtext5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.98"
android:gravity="right"
android:text="20000"
android:textAlignment="center"
android:textColor="#color/colorFontheader"
android:textSize="22dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="180dp"
android:background="#ffffff"
android:orientation="horizontal"
android:padding="1dp"
>
<TextView
android:id="#+id/firstcardtext6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:text="TextView:"
android:textAlignment="center"
android:textColor="#color/colorFontblack"
android:textSize="22dp"
android:textStyle="bold" />
<TextView
android:id="#+id/firstcardtext7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="TextView"
android:textAlignment="center"
android:textColor="#color/colorFontheader"
android:textSize="22dp"
android:textStyle="bold" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
recycler adapter code:
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.List;
public class Readapter extends RecyclerView.Adapter<Readapter.ProductViewHolder> {
//this context we will use to inflate the layout
private Context mCtx;
//we are storing all the products in a list
private List<Front> productList;
//getting the context and product list with constructor
public Readapter(Context mCtx, List<Front> productList) {
this.mCtx = mCtx;
this.productList = productList;
}
#Override
public ProductViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//inflating and returning our view holder
LayoutInflater inflater = LayoutInflater.from(mCtx);
View view=LayoutInflater.from(parent.getContext()).inflate(R.layout.layoutte,parent,false);
return new ProductViewHolder(view);
}
#Override
public void onBindViewHolder(ProductViewHolder holder, int position) {
//getting the product of the specified position
Front product = productList.get(position);
//binding the data with the viewholder views
holder.textView1.setText(product.getbud());
holder.textView2.setText(product.getbudnum());
holder.textView3.setText(product.gettosp());
holder.textView4.setText(product.gettospnum());
holder.textView5.setText(product.getrem());
holder.textView6.setText(product.getremnum());
holder.textView7.setText(product.getremnums());
}
#Override
public int getItemCount() {
return productList.size();
}
class ProductViewHolder extends RecyclerView.ViewHolder {
TextView textView1, textView2, textView3, textView4, textView5,textView6,textView7;
public ProductViewHolder(View itemView) {
super(itemView);
textView1 = itemView.findViewById(R.id.firstcardtext);
textView2 = itemView.findViewById(R.id.firstcardtext2);
textView3 = itemView.findViewById(R.id.firstcardtext3);
textView4 = itemView.findViewById(R.id.firstcardtext4);
textView5 = itemView.findViewById(R.id.firstcardtext5);
textView6 = itemView.findViewById(R.id.firstcardtext6);
textView7 = itemView.findViewById(R.id.firstcardtext7);
}
}
}
Mainactivity code(add datas):
recyclerView=(RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
productList =new ArrayList<>();
productList.add(new
Front("tested1","tested","tested","tested","tested","tested","tested"));
productList.add(new
Front("tested2","tested","tested","tested","tested","tested","tested"));
productList.add(new
Front("tested3","tested","tested","tested","tested","tested","tested"));
productList.add(new Front("tested4","tested","tested","tested","tested","tested","tested"));
Readapter adapter=new Readapter(this,productList);
recyclerView.setAdapter(adapter);
only two cards are visible in screen.another two cards not visibled.fixed height datas only showed.(not scrolled).
only test1 and test2 datas visible in screen another test3 abd test4 not viewd and scrolled .
appbar xml code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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"
tools:context="com.example.suranpc..MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
<android.support.design.widget.TabLayout
android:background="#color/colorTabbg"
app:tabSelectedTextColor="#color/colorFontwhite"
app:tabIndicatorColor="#color/colorFontwhite"
app:tabIndicatorHeight="4dp"
app:tabTextColor="#color/colorFontblack"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
app:tabGravity="fill"
android:id="#+id/tbl_pages"/>
<!-- <tabbed pane" />-->
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="#+id/vp_pages"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#android:drawable/ic_dialog_email" />
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
tabpane code in mainactivity
//the tabpane>
ViewPager vp_pages= (ViewPager) findViewById(R.id.vp_pages);
PagerAdapter pagerAdapter=new FragmentAdapter(getSupportFragmentManager());
vp_pages.setAdapter(pagerAdapter);
TabLayout tbl_pages= (TabLayout) findViewById(R.id.tbl_pages);
final int[]ICONS=new int[]{
R.drawable.ic_menu_camera, R.drawable.ic_menu_camera, R.drawable.ic_menu_camera, R.drawable.ic_menu_camera,
};
tbl_pages.setupWithViewPager(vp_pages);
tbl_pages.getTabAt(0).setIcon(ICONS[0]);
tbl_pages.getTabAt(1).setIcon(ICONS[1]);
tbl_pages.getTabAt(2).setIcon(ICONS[2]);
tbl_pages.getTabAt(3).setIcon(ICONS[3]);
//<tabpane>
Try this just Change this in your cardview design xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:padding="16dp"
app:cardCornerRadius="3dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#ffffff"
android:orientation="horizontal"
android:padding="16dp"
>
<TextView
android:id="#+id/firstcardtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="TextView"
android:textColor="#color/colorFontblack"
android:textSize="20dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="60dp"
android:background="#ffffff"
android:orientation="horizontal"
android:padding="4dp"
>
<TextView
android:id="#+id/firstcardtext2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:text="TextView :"
android:textAlignment="center"
android:textColor="#color/colorFontblack"
android:textSize="22dp"
android:textStyle="bold" />
<TextView
android:id="#+id/firstcardtext3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.91"
android:gravity="right"
android:text="TextView"
android:textAlignment="center"
android:textColor="#color/colorPrimaryDark"
android:textSize="22dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="120dp"
android:background="#ffffff"
android:orientation="horizontal"
android:padding="1dp"
>
<TextView
android:id="#+id/firstcardtext4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.92"
android:gravity="left"
android:text="TextView:"
android:textAlignment="center"
android:textColor="#color/colorFontblack"
android:textSize="22dp"
android:textStyle="bold" />
<TextView
android:id="#+id/firstcardtext5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.98"
android:gravity="right"
android:text="20000"
android:textAlignment="center"
android:textColor="#color/colorFontheader"
android:textSize="22dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="180dp"
android:background="#ffffff"
android:orientation="horizontal"
android:padding="1dp"
>
<TextView
android:id="#+id/firstcardtext6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:text="TextView:"
android:textAlignment="center"
android:textColor="#color/colorFontblack"
android:textSize="22dp"
android:textStyle="bold" />
<TextView
android:id="#+id/firstcardtext7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="TextView"
android:textAlignment="center"
android:textColor="#color/colorFontheader"
android:textSize="22dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
EDIT
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E0E0E0"
tools:context="com.example.suranpc.recy.MainActivity">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginTop="120dp"
android:scrollbars="vertical" />
</LinearLayout>
Display content main xml behalf of tabpane fragment(home page xml).use fragment it works.
Getting NullPointerExceptionwhen trying to add a toolbar which is been defined in a layout file other than main design xml file. I keep getting the following error:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.support.v7.widget.Toolbar.findViewById(int)' on a null object reference
Here is my code
public class History_List_Details_Fragment extends Fragment {
Histroy_List_Model histroyListModel;
public History_List_Details_Fragment() {
}
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
histroyListModel = getArguments().getParcelable("historydetail");
String title=histroyListModel.getShared_title();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
super.onCreate(savedInstanceState);
View rootView = inflater.inflate(R.layout.history_list_details_fragment, container, false);
Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.app_bar);
initializeListnersForToolbar(toolbar);
initializeViews(rootView);
return rootView;
}
private void initializeViews(View rootView) {
TextView titleText = (TextView) rootView.findViewById(R.id.txtTitle);
titleText.setText(histroyListModel.getShared_title());
TextView messageTExt = (TextView) rootView.findViewById(R.id.txtMessage);
titleText.setText(histroyListModel.getShared_message());
}
private void initializeListnersForToolbar(Toolbar toolbar){
((TextView) toolbar.findViewById(R.id.tool_bar_text_head)).setText(getResources().getString(R.string.friends));
((ImageView) toolbar.findViewById(R.id.tool_bar_back_arrow)).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Fragment fragment=new History_List_Fragment();
Utilities.getInstance(getActivity()).change_HomPage_Fragment(
fragment, "History_List_Fragment", getActivity());
}
});
}
}
History_List_Details_Fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="68dp"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Title"
android:id="#+id/txtTitle"
android:layout_gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="horizontal"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Message"
android:id="#+id/txtMessage"
android:layout_gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Duration"
android:id="#+id/txtDuration"
android:layout_gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/lstMembers"></ListView>
</LinearLayout>
</LinearLayout>
How can I fix this error?
Add Toolbar in "history_list_details_fragment" with id "app_bar"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
local:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="68dp"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Title"
android:id="#+id/txtTitle"
android:layout_gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="horizontal"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Message"
android:id="#+id/txtMessage"
android:layout_gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Duration"
android:id="#+id/txtDuration"
android:layout_gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/lstMembers"></ListView>
</LinearLayout>
The error states clearly. Inside history_list_details_fragment.xml there is no Toolbar. Try to add it.
Or more probably the Toolbar is in you Activity layout, so init it inside Activity.
In activity I use SearchView and I want to implement dropdown when any result occurred is it possible ?? thanks in adavance.
searchActivity.java code
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.search_activity);
isSearchVisible = false;
isHomeVisible = true;
mActivity = this;
mContext = getApplicationContext();
mSearchView = (SearchView) findViewById(R.id.m_searchview);
edtFromDate = (EditText) findViewById(R.id.edt_from_date);
edtEndDate = (EditText) findViewById(R.id.edt_end_date);
btnSearchNow = (Button) findViewById(R.id.btn_search_now);
int searchPlateId = mSearchView.getContext().getResources()
.getIdentifier("android:id/search_plate", null, null);
View searchPlateView = mSearchView.findViewById(searchPlateId);
if (searchPlateView != null) {
searchPlateView.setBackgroundColor(Color.WHITE);
}
}
search_activity.xml code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="#color/main_background"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="#dimen/activity_horizontal_margin">
<SearchView android:id="#+id/m_searchview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:closeIcon="#drawable/close"
android:searchIcon="#drawable/search_blue"
android:padding="2dp"
android:background="#drawable/editext_background"
android:layout_marginBottom="#dimen/activity_horizontal_margin"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title_from_date"
android:textSize="20sp"
android:textColor="#color/colorAccent"
android:layout_marginBottom="15dp"/>
<EditText android:id="#+id/edt_from_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:drawableRight="#drawable/calendar"
android:paddingRight="20dp"
android:enabled="false"
style="#style/loginEditTextView"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title_end_date"
android:textSize="20sp"
android:textColor="#color/colorAccent"
android:layout_marginBottom="15dp"/>
<EditText android:id="#+id/edt_end_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:drawableRight="#drawable/calendar"
android:paddingRight="20dp"
android:enabled="false"
style="#style/loginEditTextView"/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button android:id="#+id/btn_search_now"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#drawable/search_now"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
here's manifest code for manifest app
<activity android:name=".activity.SearchActivity"
android:label="#string/title_search_activity"
android:configChanges="orientation"></activity>
I have 2 fragments, and want to do a shared element transition between them.
The item in an recyclerview, with an adapter, contains a textview that should be animated to an edittext in the next fragment.
The recyclerview is in an fragment too.
Here's my code:
item layout for viewholder from adapter:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/row_container"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:background="#FAFAFA"
android:elevation="0dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"
android:elevation="0dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:elevation="0dp"
>
<RelativeLayout
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#null"
android:elevation="0dp"
android:layout_centerVertical="true"
>
<ImageButton
android:id="#+id/notify_btn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_bookmark_black_24dp"
android:background="#null"
android:tint="#9E9E9E"
android:layout_centerInParent="true"
/>
</RelativeLayout>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="20dp"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_alignParentTop="true"
android:maxLines="1"
android:ellipsize="end"
android:transitionName="title"
/>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/text"
android:layout_below="#id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="20dp"
android:textSize="15sp"
android:maxLines="2"
android:layout_alignParentBottom="true"
android:textColor="#android:color/black"
android:ellipsize="end"
android:transitionName="text"
/>
</RelativeLayout>
<ImageView
android:id="#+id/fav"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_margin="5dp"
android:visibility="invisible"
android:src="#drawable/ic_star_black_24dp"
/>
</RelativeLayout>
MyAdapter class, the item row click:
row.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Fragment frag = new Fragment_Notice();
int tin_title = Integer.parseInt(String.valueOf(title.getText().length()));
if ( (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) &&
( SharedPrefHelper.getBool("shared_transition") == true) &&
( tin_title >= 1 ) ) {
//Exit transition for old fragment
frag.setSharedElementReturnTransition(TransitionInflater.from(context).inflateTransition(R.transition.title_transform));
frag.setExitTransition(TransitionInflater.from(context).inflateTransition(android.R.transition.explode));
//Enter transition for new fragment
frag.setSharedElementEnterTransition(TransitionInflater.from(context).inflateTransition(R.transition.title_transform));
frag.setEnterTransition(TransitionInflater.from(context).inflateTransition(android.R.transition.explode));
ft.replace(R.id.container, frag, "NoticeTag")
.addToBackStack(null)
.addSharedElement(title, "title")
.commit();
} else {
int open = R.anim.abc_fade_in;
int close = R.anim.abc_fade_out;
ft.setCustomAnimations(open, close, open, close)
.replace(R.id.container, frag, "NoticeTag")
.addToBackStack(null)
.commit();
}
}
});
Layout from final fragment:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginRight="10dp"
android:padding="10dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<EditText
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:nextFocusForward="#id/text"
android:imeOptions="actionNext"
android:singleLine="true"
android:ems="16"
android:hint="#string/title"
android:textColor="#212121"
android:textColorHint="#757575"
android:background="#null"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:scrollbars="horizontal"
android:transitionName="title"
/>
<EditText
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/text"
android:textColor="#212121"
android:textColorHint="#757575"
android:background="#null"
android:layout_marginLeft="2dp"
android:transitionName="text"
/>
<View
android:id="#+id/line"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:elevation="0dp"
android:background="#color/grey"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
>
<ImageButton
android:id="#+id/fav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_star_black_24dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:padding="5dp"
android:background="?android:attr/selectableItemBackground"
android:tint="#9E9E9E"
/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="top"
android:id="#+id/snackbar">
</android.support.design.widget.CoordinatorLayout>
The textview doesnt animate to an edittext.
The explode animation appears.
Between activities the animation works.
Any suggestions how to fix?